日志
2.4.2 多页对话框
2015-11-27 13:41
//UIStackedDialog.h
#ifndef UISTACKDIALOG_H #define UISTACKDIALOG_H #include <QDialog> #include <QStackedWidget> #include <QListWidget> #include <QLabel> class UIStackedDialog : public QDialog { Q_OBJECT public: explicit UIStackedDialog(QWidget *parent=0,Qt::WindowFlags f=0); private: QLabel *m_pLabel1; QLabel *m_pLabel2; QLabel *m_pLabel3; QListWidget *m_pListWidget; QStackedWidget *m_pStackWidget; }; #endif // STACKDIALOG_H //UIStackedDialog.cpp #include "UIStackedDialog.h" #include <QHBoxLayout> UIStackedDialog::UIStackedDialog(QWidget *parent,Qt::WindowFlags f) : QDialog(parent,f) { setWindowTitle(tr("堆栈窗体")); m_pListWidget = new QListWidget(this); m_pListWidget->insertItem(0,tr("窗口一")); m_pListWidget->insertItem(1,tr("窗口二")); m_pListWidget->insertItem(2,tr("窗口三")); m_pLabel1 = new QLabel(tr("标签一")); m_pLabel2 = new QLabel(tr("标签二")); m_pLabel3 = new QLabel(tr("标签三")); m_pStackWidget = new QStackedWidget(this); m_pStackWidget->addWidget(m_pLabel1); m_pStackWidget->addWidget(m_pLabel2); m_pStackWidget->addWidget(m_pLabel3); QHBoxLayout *pMainLayout = new QHBoxLayout(this); pMainLayout->setMargin(5); pMainLayout->setSpacing(5); pMainLayout->addWidget(m_pListWidget); pMainLayout->addWidget(m_pStackWidget, 0 ,Qt::AlignHCenter); //setStretchFactor()调整控件的大小比例 pMainLayout->setStretchFactor(m_pListWidget, 1); pMainLayout->setStretchFactor(m_pStackWidget, 3); connect(m_pListWidget,SIGNAL(currentRowChanged(int)), m_pStackWidget,SLOT(setCurrentIndex(int))); } //main.cpp #include <QApplication> #include "UIStackedDialog.h" #include <QTextCodec> int main(int argc,char** argv) { QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); QApplication app(argc,argv); UIStackedDialog dlg; dlg.show(); return app.exec(); } |
下一篇: 2.5 动态对话框
上一篇: 2.4.1 可扩展对话框