具有QPushButton的QT GridLayout

时间:2019-07-19 08:51:00

标签: qt

我在代码中模拟功能区样式。为此,我也使用QGridLayout。 但是我有一个问题。

| colspan 3 QLineEdit |

| QLabel | QLineEdit | QLabel | QLineEdit | QLabel | QLineEdit |

| QLabel | QComboBox | QLabel | QLineEdit |

这看起来像: Perfect

现在,我需要在编辑右侧添加一个QPushButton,因此我尝试将按钮添加到网格中。

myBootGridLayout->addWidget(btnSelBootImagePath,0,3);

我还尝试了0.4以确保它不是电池问题。

| colspan 3 QLineEdit | QPushButton |

| QLabel | QLineEdit | QLabel | QLineEdit | QLabel | QLineEdit |

| QLabel | QComboBox | QLabel | QLineEdit |

但是在添加QPushButton之后,网格看起来像:

Damaged

看起来QPushButton杀死了GRidLayout。我试图将按钮设置为固定高16,这没有帮助。按钮放置位置非常错误。

Wrong Position

最后,我尝试使用CSS将按钮的边距和填充设置为0。同样无效。

是否有解决方案?我的目标是拥有QLineEdit,并在右侧有一个按钮来选择一个文件。两者都具有相同的高度。

我的ui中有几个GRidLayouts,并且一切正常,只有带有QPushButton的GRidLayouts。

完整的网格代码为:

     QGridLayout *myBootGridLayout = new QGridLayout(this);
     QWidget * wdgBootFeatues = new QWidget(this);


     imagePathBootEdit = new QLineEdit(this);
     imagePathBootEdit->setReadOnly(true);
     imagePathBootEdit->setMaximumWidth(300);
     imagePathBootEdit->setMinimumWidth(300);
     myBootGridLayout->addWidget(imagePathBootEdit,0,0,1,3);

        //Problem
         QPushButton *btnSelBootImagePath = new QPushButton(this);

         btnSelBootImagePath->setText(tr("..."));
         //btnSelBootImagePath->setMinimumWidth(16);
         btnSelBootImagePath->setMaximumWidth(32);
         //btnSelBootImagePath->setMinimumHeight(16);
         btnSelBootImagePath->setMaximumHeight(16);
         //connect(btnSelBootImagePath, SIGNAL(clicked()),this, SLOT(clickedSelBootImagePath()));
         //btnSelBootImagePath->setStyleSheet("QPushButton{padding:0px;margin:0px;}");
         myBootGridLayout->addWidget(btnSelBootImagePath,0,3);




     QLabel *labelDeveloperID = new QLabel(this);
     labelDeveloperID->setText(tr("Developer ID:"));
     myBootGridLayout->addWidget(labelDeveloperID,1,0);
     developerIDBootEdit = new QLineEdit(this);
     developerIDBootEdit->setMinimumWidth(100);
     developerIDBootEdit->setMaximumWidth(100);
     //connect(developerIDBootEdit,SIGNAL(textChanged(QString)),this,SLOT(bootDeveloperIDchanged(QString)));
     myBootGridLayout->addWidget(developerIDBootEdit,1,1);

     QLabel *labelSectos = new QLabel(this);
     labelSectos->setText(tr("Sectors:"));
     myBootGridLayout->addWidget(labelSectos,1,2);
     sectorsBootEdit = new QLineEdit(this);
     sectorsBootEdit->setMinimumWidth(80);
     sectorsBootEdit->setMaximumWidth(80);
     //connect(sectorsBootEdit,SIGNAL(textChanged(QString)),this,SLOT(bootSectorschanged(QString)));
     myBootGridLayout->addWidget(sectorsBootEdit,1,3);

     QLabel *labelLoadSegment = new QLabel(this);
     labelLoadSegment->setText(tr("Load segment:"));
     myBootGridLayout->addWidget(labelLoadSegment,1,4);
     loadSegmentBootEdit = new QLineEdit(this);
     loadSegmentBootEdit->setMinimumWidth(80);
     loadSegmentBootEdit->setMaximumWidth(80);
     //connect(edBootLoadSegment,SIGNAL(textChanged(QString)),this,SLOT(bootLoadSegmentchanged(QString)));
     myBootGridLayout->addWidget(loadSegmentBootEdit,1,5);

     QLabel *labelEmulation = new QLabel(this);
     labelEmulation->setText(tr("Emulation Type:"));
     myBootGridLayout->addWidget(labelEmulation,2,0);
     emulationTypeBootCombo = new QComboBox();
     emulationTypeBootCombo->setMinimumWidth(100);
     emulationTypeBootCombo->setMaximumWidth(100);
     emulationTypeBootCombo->addItem(tr("No emulaton (NT/2000/XP)"));
     emulationTypeBootCombo->addItem(tr("Floppy 1.2MB"));
     emulationTypeBootCombo->addItem(tr("Floppy 1.44MB (95/98/ME)"));
     emulationTypeBootCombo->addItem(tr("Floppy 2.88MB"));
     emulationTypeBootCombo->addItem(tr("Hard Disk"));
     //connect(emulationTypeBootCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(bootEmulationTypeChanged(int)));
     myBootGridLayout->addWidget(emulationTypeBootCombo,2,1);

     QLabel *labelPlatfom = new QLabel(this);
     labelPlatfom->setText(tr("Platform:"));
     myBootGridLayout->addWidget(labelPlatfom,2,2);
     platformBootCombo = new QComboBox();
     platformBootCombo->setMinimumWidth(100);
     platformBootCombo->setMaximumWidth(100);
     platformBootCombo->addItem(tr("x86 - 32"));
     platformBootCombo->addItem(tr("x86 - 64"));
     platformBootCombo->addItem(tr("PowerPC"));
     platformBootCombo->addItem(tr("MAC"));
     //connect(platformBootCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(bootPlatformChanged(int)));
     myBootGridLayout->addWidget(platformBootCombo,2,3);

//Added for testing button problem
     myBootGridLayout->setRowMinimumHeight(0,25);
     myBootGridLayout->setRowMinimumHeight(1,25);
     myBootGridLayout->setRowMinimumHeight(2,25);
     myBootGridLayout->setContentsMargins(3,0,0,0);

//Add Lyout to ui
     wdgBootFeatues->setLayout(myBootGridLayout);
     wdgBootFeatues->setFixedHeight(80);
     ui->ribbonTabWidget->addWidgetGroup("Boot Disc", "El-Torito", wdgBootFeatues);

0 个答案:

没有答案