2011-02-18 105 views
0

根据QT4文档QDialog的sizeGrip在默认情况下是禁用的,但是我的反正有一个。所以我尝试运行setSizeGripEnabled(false),我仍然有一个。所以,其他的东西一定会造成这种情况,但我不知道是什么。如果它很重要我的对话框目前没有父母,因为我正在设计/测试它。我不明白为什么这很重要,但只是提到它,以防万一它出于某种原因。这里是我的完整代码:为什么我不能将我的QDialog设置为没有sizeGrip?

#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

你在哪个平台上?当使用setFixedSize时,对话框是可调整大小的,还是仅仅是绘制的手柄,而没有功能? – 2011-02-19 10:23:47

回答

1

设置父应该不会影响任何东西。

您可以通过使用setFixedSize(width,height)将对话框设置为固定大小来解决此问题。

但是,这绝对是一个工作。

+0

我也试过,它不起作用:(我想我可能会被卡住。 – kryptobs2000 2011-02-19 00:43:55

相关问题