0
我試圖將圖像插入到我的項目中。我寫了下面的代碼:縮小圖像的大小
void MainWindow::on_Layer_Updated(int arg1)
{
if(ui->scrnCheck1->checkState() == Qt::Checked && ui->insCheck1->checkState() == Qt::Checked && ui->scrnCheck2->checkState() == Qt::Checked && ui->sheathCheck1->checkState() == Qt::Checked
&& ui->insCheck3->checkState() == Qt::Checked && ui->concentricCheck2->checkState() == Qt::Checked && ui->insCheck2->checkState() == Qt::Checked && ui->armorCheck->checkState() == Qt::Checked
&& ui->jacketCheck->checkState() == Qt::Checked)
{
QImage image;
image.load(":/CondScrnInsScrnSheathInsCentricInsWiresArmJacket.png");
ui->label_2->setPixmap(QPixmap::fromImage(image));
ui->frame_10->setMinimumHeight(image.size().height() + 20);
ui->groupBox_3->setMinimumHeight(ui->frame_10->size().height() + 20);
}
當我跑步時圖像越來越彈出的程序,但圖像的尺寸較大,它與另一個網格重疊。所以我減少了mainwindow.ui中的圖像視圖 - >高度尺寸。然後只顯示圖像的一半。如何調整圖像,使其不會與其他網格重疊?
你可以直接用QPixmap(「:image」)創建一個QPixmap,而不是QImage並轉換它。而且你是否嘗試過設置'QLabel-> setScaledContents(true)'? – jdi