一、对话框部分常用内容
颜色对话框、文件对话框、字体对话框、输入对话框、消息对话框、进度对话框、错误对话框、向导对话框。 二、代码部分1 //widget.h 2 #ifndef MYWIDGET_H 3 #define MYWIDGET_H 4 5 #include6 #include 7 8 namespace Ui { 9 class MyWidget; 10 } 11 12 class MyWidget : public QWidget 13 { 14 Q_OBJECT 15 16 public: 17 explicit MyWidget(QWidget *parent = 0); 18 ~MyWidget(); 19 20 private slots: 21 void on_pushButton_clicked(); 22 23 void on_pushButton_4_clicked(); 24 25 void on_pushButton_2_clicked(); 26 27 void on_pushButton_5_clicked(); 28 29 void on_pushButton_3_clicked(); 30 31 void on_pushButton_6_clicked(); 32 33 void on_pushButton_7_clicked(); 34 35 void on_pushButton_8_clicked(); 36 37 private: 38 Ui::MyWidget *ui; 39 QWizardPage *createPage1(); 40 QWizardPage *createPage2(); 41 QWizardPage *createPage3(); 42 }; 43 44 #endif // MYWIDGET_H 45 46 47 //widget.cpp 48 #include "mywidget.h" 49 #include "ui_mywidget.h" 50 #include 51 #include 52 #include 53 #include 54 #include 55 #include 56 #include 57 #include 58 #include 59 60 MyWidget::MyWidget(QWidget *parent) : 61 QWidget(parent), 62 ui(new Ui::MyWidget) 63 { 64 ui->setupUi(this); 65 } 66 67 MyWidget::~MyWidget() 68 { 69 delete ui; 70 } 71 72 //颜色对话框 73 void MyWidget::on_pushButton_clicked() 74 { 75 // QColor color = QColorDialog::getColor(Qt::red, this, tr("颜色对话框"), QColorDialog::ShowAlphaChannel); 76 // qDebug()<<"color: "< pushButton_2->setFont(font); 98 else qDebug()< setWindowTitle(tr("错误信息对话框"));175 dialog->showMessage(tr("这里是出错信息!"));176 }177 178 QWizardPage *MyWidget::createPage1()179 {180 QWizardPage *page = new QWizardPage;181 page->setTitle(tr("介绍"));182 return page;183 }184 185 QWizardPage *MyWidget::createPage2()186 {187 QWizardPage *page = new QWizardPage;188 page->setTitle(tr("用户选择信息"));189 return page;190 }191 192 QWizardPage *MyWidget::createPage3()193 {194 QWizardPage *page = new QWizardPage;195 page->setTitle(tr("结束"));196 return page;197 }198 199 //相对对话框200 void MyWidget::on_pushButton_8_clicked()201 {202 QWizard wizard(this);203 wizard.setWindowTitle(tr("向导对话框"));204 wizard.addPage(createPage1());205 wizard.addPage(createPage2());206 wizard.addPage(createPage3());207 wizard.exec();208 }
#include "mywidget.h" #includeint main(int argc, char *argv[]) { QApplication a(argc, argv); MyWidget w; w.show(); return a.exec(); }
ui样子