C++ GUI Qt4编程(13)-6.2preferencedialog
1. 主要介绍了QStackedLayout、QListWidget、QDialogButtonBox的简单用法。
2. QStackedLayout:
要使某个特定的子窗口部件可见,可以用setCurrentIndex()函数调用页号来实现。
使用indexOf()可以获取子窗口部件的页号。
3. 创建此对话框的简单步骤:
1) 建立一个QListWidget和一个QStackedWidget,并添加到QGridLayout布局中。
2) 在QListWidget中用addItem(),添加新的项目(或者说是新列表?)。
3) 在QStackedWidget中,新建QWisget类的分页,并用自窗口部件和布局来填充分页。
4) 在QGridLayout中添加QDialogButtonBox按钮。
5) 将列表窗口部件的currentRowChanged(int)信号和分组窗口部件的setCurrentIndex(int)
槽连接起来。实现单击列表,在分组窗口中显示对应的信息。
6) 把列表框的currentRow属性值设为0。
4. 使用QTabWidget会比此方法更简单。
5. preferencedialog.cpp
/**/
#include "preferencedialog.h" #include <QListWidget>
#include <QStackedLayout>
#include <QGridLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDialogButtonBox> PreferenceDialog::PreferenceDialog(QWidget *parent)
: QWidget(parent)
{
createAppearancePage();
createWebBrowserPage();
createMailAndNewsPage();
createAdvancedPage(); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel); listWidget = new QListWidget;
listWidget->addItem(tr("Appearance"));
listWidget->addItem(tr("Web Browse"));
listWidget->addItem(tr("Mail & News"));
listWidget->addItem(tr("Advanced")); stackedLayout = new QStackedLayout;
stackedLayout->addWidget(appearancePage);
stackedLayout->addWidget(webBrowserPage);
stackedLayout->addWidget(mailAndNewsPage);
stackedLayout->addWidget(advancedPage); connect(listWidget, SIGNAL(currentRowChanged(int)),
stackedLayout, SLOT(setCurrentIndex(int))); QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(listWidget, , );
mainLayout->addLayout(stackedLayout, , );
mainLayout->addWidget(buttonBox, , , , ); setLayout(mainLayout); listWidget->setCurrentRow(); /*设置起始页*/
} void PreferenceDialog::createAppearancePage()
{
appearancePage = new QWidget; QLabel *appearanceLabel = new QLabel(tr("appearance"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(appearanceLabel); appearancePage->setLayout(layout);
} void PreferenceDialog::createWebBrowserPage()
{
webBrowserPage = new QWidget; QPushButton *webBrowserButton = new QPushButton(tr("web browser"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(webBrowserButton); webBrowserPage->setLayout(layout);
} void PreferenceDialog::createMailAndNewsPage()
{
mailAndNewsPage = new QWidget; QLabel *mailAndNewsLabel = new QLabel(tr("mail & news"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mailAndNewsLabel); mailAndNewsPage->setLayout(layout);
} void PreferenceDialog::createAdvancedPage()
{
advancedPage = new QWidget; QPushButton *advancedButton = new QPushButton(tr("advanced"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(advancedButton); advancedPage->setLayout(layout);
}
6. preferencedialog.h
/**/
#ifndef PREFERENCEDIALOG_H
#define PREFERENCEDIALOG_H #include <QWidget> class QListWidget;
class QStackedLayout;
class QDialogButtonBox; class PreferenceDialog : public QWidget
{
Q_OBJECT public:
PreferenceDialog(QWidget *parent = ); private:
QListWidget *listWidget;
QStackedLayout *stackedLayout;
QWidget *appearancePage;
QWidget *webBrowserPage;
QWidget *mailAndNewsPage;
QWidget *advancedPage;
QDialogButtonBox *buttonBox; void createAppearancePage();
void createWebBrowserPage();
void createMailAndNewsPage();
void createAdvancedPage();
}; #endif /*PREFERENCEDIALOG_H*/
7. main.cpp
/**/
#include <QApplication>
#include "preferencedialog.h" int main(int argc, char *argv[])
{
QApplication app(argc, argv); PreferenceDialog dialog;
dialog.show(); return app.exec();
}
8. 效果




C++ GUI Qt4编程(13)-6.2preferencedialog的更多相关文章
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar
1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...
- C++ GUI Qt4编程(08)-3.2spreadsheet-resource
1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...
- C++ GUI Qt4编程(07)-3.1menu
1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...
- C++ GUI Qt4编程(03)-1.3layout
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...
- C++ GUI Qt4编程(02)-1.2quit
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...
- C++ GUI Qt4编程(01)-1.1Hello Qt
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...
- C++ GUI Qt4编程-创建自定义窗口部件
C++ GUI Qt4编程-创建自定义窗口部件 Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...
- C++ GUI Qt4 编程 (第二版)
[加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...
随机推荐
- 利用GeoServer发布web地图服务
参考: http://www.cnblogs.com/beniao/archive/2011/01/11/1931028.html http://www.cnblogs.com/LBSer/p/445 ...
- 命令之 ulimit
help ulimit help ulimit ulimit: ulimit [-SHacdefilmnpqrstuvx] [limit] Modify shell resource limits. ...
- 编写高质量代码改善C#程序的157个建议——建议10: 创建对象时需要考虑是否实现比较器
建议10: 创建对象时需要考虑是否实现比较器 有对象的地方就会存在比较,在.NET的世界中也一样.举个最简单的例子,在UI中,有一个10个人的Salary列表.根据排序的需要,列表要支持针对基本工资来 ...
- C# How To Read .xlsx Excel File With 3 Lines Of Code
Download Excel.zip - 9.7 KB Download ExcelDLL.zip - 3.7 KB Introduction We produce professional busi ...
- xubuntu14.04LTS安装steam后运行的错误解决办法
我在ubuntu14.10中没碰到过这个问题,但在xubuntu14.04LTS中碰到 Steam needs to install these additional packages: libgl1 ...
- It企业的上市与退市
目前我国的it上市公司有同方股份.华胜天成.长城电脑.航天信息.用友软件.中国软件.东软集团.长电科技.华东科技.航天长峰.航天科技.士兰微.上海贝岭等等. 一般来讲公司上市是为了融资,一是为了解决资 ...
- sqlServer2008技术内幕笔记总结(实用的sql方法总结)
over函数的使用: 1.可以实现基于什么求和,省去group by: select xingming,xingbie,COUNT(*) over() as '总人数' from jbxx_xuesh ...
- Task ContinueWith
前正无生意,且记Task.ContinueWith之用法. using System; using System.Collections.Generic; using System.Diagnosti ...
- 【大数据之数据仓库】GreenPlum优化器对比测试
在< [大数据之数据仓库]选型流水记>一文中有提及,当时没有测试GreenPlum的quicklz压缩算法和ORCA查询优化器,考虑到quicklz压缩算法因为版权问题不会开源(详情请参阅 ...
- mac下redis和zookeeper启动及测试命令
mac下启动命令: sudo su - root cd /usr/local/bin/ ./redis-server ../etc/redis.conf cd /software/zook ...