我正在尝试在QDialog窗口中调整LineEdit和PushButton宽度。 LineEdit应该比按钮宽20倍,所以它足够长以显示整个路径。下面是我的代码,我尝试了几种方法,但它们都有类似的布局(见截图)。我想让Option窗口至少宽2倍,以使LineEdit足够宽。我该怎么做?
这是我的代码:
this->setWindowTitle(tr("Options"));
QGridLayout* logLayout = new QGridLayout;
QLineEdit _logPathLE = new QLineEdit;
logLayout->addWidget(_logPathLE, 0, 0);
logLayout->setColumnStretch(0, 20); // 1st: try with setStretch
//_logPathLE->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); // 2nd try with setSizePolicy
//logLayout->addWidget(logLocation, 0, 0, 0, 20); // 3rd: try with span multiple columns
QPushButton* browseFolder = new QPushButton(tr("..."));
logLayout->addWidget(browseFolder, 0, 1);
logLayout->setColumnStretch(1, 1);
//browseFolder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
//logLayout->addWidget(browseFolder, 0, 20, 0, 1);
QGroupBox* optGroupBox = new QGroupBox(tr("Log location"));
optGroupBox->setLayout(logLayout);
QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(btns, SIGNAL(accepted()), this, SLOT(accept()));
connect(btns, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout* options = new QVBoxLayout;
options->addWidget(optGroupBox);
options->addWidget(btns);
this->setLayout(options);