根据QT4文档,默认情况下,QDialog的sizeGrip被禁用,但无论如何我都有。所以我尝试运行setSizeGripEnabled(false),我仍然有一个。所以,其他一些必须导致这一点,但我不知道是什么。如果重要,我的对话框目前没有父对象,因为我正在设计/测试它。我不明白为什么这应该重要,但只是提到它,以防它出于某种原因。这是我的完整代码:
#include "QtGui"
//#include "clposter.h"
void add_new_account()
{
// CHECK::Make sure this process is destroyed when it's supposed to be
// TODO::connect signals to slots
//
// Create Dialog box to add user account
QDialog *accountDialog = new QDialog();
accountDialog->setModal(true);
accountDialog->setWindowTitle("Add New Account");
accountDialog->setSizeGripEnabled(false);
// Create Main Layout
QVBoxLayout *mainVBox = new QVBoxLayout(accountDialog);
QLabel *accountNameLabel = new QLabel(accountDialog);
accountNameLabel->setText("Account:");
QLineEdit *accountName = new QLineEdit(accountDialog);
accountName->setMinimumWidth(250);
QLabel *accountPassLabel = new QLabel(accountDialog);
accountPassLabel->setText("Password:");
QLineEdit *accountPass = new QLineEdit(accountDialog);
accountPass->setEchoMode(QLineEdit::Password);
// NOTE::May want to use standard dialog buttons instead
QPushButton *okButton = new QPushButton("Ok", accountDialog);
QPushButton *cancelButton = new QPushButton("Cancel", accountDialog);
// Connect signals to slots
// Set layout
// CHECK::Should accountDialog be the parent for these? I get a warning that they cannot be set
// because accountDialog already has a layout, which is expected, but I want them to
// automatically be deleted when accountDialog is so it makes sense to make it the parent.
QVBoxLayout *labelsVBox = new QVBoxLayout(accountDialog);
labelsVBox->addWidget(accountNameLabel);
labelsVBox->addWidget(accountPassLabel);
QVBoxLayout *lineEditsVBox = new QVBoxLayout(accountDialog);
lineEditsVBox->addWidget(accountName);
lineEditsVBox->addWidget(accountPass);
QHBoxLayout *topHBox = new QHBoxLayout(accountDialog);
topHBox->addLayout(labelsVBox);
topHBox->addLayout(lineEditsVBox);
QHBoxLayout *buttonHBox = new QHBoxLayout(accountDialog);
buttonHBox->addStretch();
buttonHBox->addWidget(okButton);
buttonHBox->addWidget(cancelButton);
mainVBox->addLayout(topHBox);
mainVBox->addLayout(buttonHBox);
accountDialog->setLayout(mainVBox);
// Show Dialog
accountDialog->exec();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//CLPoster mainWin;
//mainWin.show();
add_new_account();
return app.exec();
}
答案 0 :(得分:1)
设置父级不应影响任何内容。
您可以通过使用setFixedSize(width,height)将Dialog设置为固定大小来解决此问题;
然而,这绝对是一种解决方法。