1. 程式人生 > 其它 >自定義QDialog

自定義QDialog

技術標籤:unity

1、新建QtGUI應用,基類選擇QDialog,取消建立介面

2、建構函式中:

    setWindowTitle("Custom Dialog");

    QLabel *lbl = new QLabel("Name");
    QLineEdit *edit = new QLineEdit("");

    QPushButton *okbtn = new QPushButton("ok");
    QPushButton *cancelbtn = new QPushButton("cancel");

    QHBoxLayout *hlay1 = new QHBoxLayout();
    hlay1->addWidget(lbl);
    hlay1->addWidget(edit);

    QHBoxLayout *hlay2 = new QHBoxLayout();
    hlay2->addWidget(okbtn);
    hlay2->addWidget(cancelbtn);

    QVBoxLayout *vlay = new QVBoxLayout();
    vlay->addLayout(hlay1);
    vlay->addLayout(hlay2);

    setLayout(vlay);

3、效果

1d748acd20af946fb22c190d4c371110d4a.jpg