axylp123的个人主页

http://www.qtcn.org/bbs/u/154703  [收藏] [复制]

axylp123

  • 1

    关注

  • 1

    粉丝

  • 16

    访客

  • 等级:新手上路
  • 总积分:15
  • 男,1987-10-10

最后登录:2017-06-01

更多资料

日志

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();
}

分类:C++GUIQt4|回复:0|浏览:789|全站可见|转载
 

下一篇: 2.5 动态对话框

上一篇: 2.4.1 可扩展对话框

Powered by phpwind v8.7 Certificate Copyright Time now is:04-28 16:39
©2005-2016 QTCN开发网 版权所有 Gzip disabled