QT中QTabWidget的使用
2015-12-01 17:11
453 查看
.pro代码:
tabdialog.h:
main.cpp:
tabdialog.cpp:
图形:
![](http://img.blog.csdn.net/20151201170656382?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170708882?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170722903?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170841488?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170850069?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170857527?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170905373?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20151201170912830?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
当没有给main传参数的时候,argv中只有一个值,就是可执行的exe QT中传参数的方法见上图。
#------------------------------------------------- # # Project created by QtCreator 2015-11-30T15:19:54 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = tabdialog TEMPLATE = app SOURCES += main.cpp\ # mainwindow.cpp\ tabdialog.cpp #HEADERS += mainwindow.h HEADERS += tabdialog.h #FORMS += mainwindow.ui #QT += widgets #HEADERS = tabdialog.h \ # tabdialog.h #SOURCES = main.cpp \ # tabdialog.cpp \ # tabdialog.cpp ## install #target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/tabdialog #INSTALLS += target #wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib win32 { } DEFINES += _DEBUG VLD_PATH = C:/Program Files (x86)/Visual Leak Detector INCLUDEPATH += $VLD_PATH/include #LIBS += -L $$VLD_PATH/lib/Win32 -lvld #LIBS += -L $$VLD_PATH/lib/Win32 #LIBS += -L C:/Program Files (x86)/Visual Leak Detector/lib/Win32/vld #LIBS += -Lvld LIBS += -LC:/Program Files (x86)/Visual Leak Detector/lib/Win32/-lvld #LIBS+= -lvld # #LIBS += -L $VLD_PATH/lib/Win32/vld.lib #win32 { # CONFIG(debug, debug|release) # { ## DEFINES += _DEBUG # # vld 2.2 downloaded from http://vld.codeplex.com/ C:\Program Files (x86)\Visual Leak Detector\include # VLD_PATH = C:/Program Files (x86)/Visual Leak Detector # INCLUDEPATH += $VLD_PATH/include # LIBS += -L$VLD_PATH/lib/Win32 -lvld # } #}
tabdialog.h:
#ifndef TABDIALOG_H #define TABDIALOG_H #include <QDialog> class QDialogButtonBox; class QFileInfo; class QTabWidget; class GeneralTab : public QWidget { Q_OBJECT public: explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); }; class PermissionsTab : public QWidget { Q_OBJECT public: explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); }; class ApplicationsTab : public QWidget { Q_OBJECT public: explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); }; class TabDialog : public QDialog { Q_OBJECT public: explicit TabDialog(const QString &fileName, QWidget *parent = 0); private: QTabWidget *tabWidget; QDialogButtonBox *buttonBox; }; #endif // TABDIALOG_H
main.cpp:
//#include "mainwindow.h" //#include <QApplication> //int main(int argc, char *argv[]) //{ // QApplication a(argc, argv); // MainWindow w; // w.show(); // return a.exec(); //} #ifdef _DEBUG #include "vld.h" #endif #include <QApplication> #include "tabdialog.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QString fileName; if (argc >= 2) fileName = argv[1]; else fileName = "."; TabDialog tabdialog(fileName); tabdialog.show(); return app.exec(); }
tabdialog.cpp:
#include <QtWidgets> #include "tabdialog.h" TabDialog::TabDialog(const QString &fileName, QWidget *parent) : QDialog(parent) { QFileInfo fileInfo(fileName); tabWidget = new QTabWidget; tabWidget->addTab(new GeneralTab(fileInfo), tr("General")); tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions")); tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications")); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); //QVBoxLayout *mainLayout = new QVBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(tabWidget); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Tab Dialog")); } GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QLabel *fileNameLabel = new QLabel(tr("File Name:")); QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName()); QLabel *pathLabel = new QLabel(tr("Path:")); QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath()); pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *sizeLabel = new QLabel(tr("Size:")); qlonglong size = fileInfo.size()/1024; QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size)); sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *lastReadLabel = new QLabel(tr("Last Read:")); QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString()); lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *lastModLabel = new QLabel(tr("Last Modified:")); QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString()); lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QVBoxLayout *mainLayout = new QVBoxLayout; //QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(fileNameLabel); mainLayout->addWidget(fileNameEdit); mainLayout->addWidget(pathLabel); mainLayout->addWidget(pathValueLabel); mainLayout->addWidget(sizeLabel); mainLayout->addWidget(sizeValueLabel); mainLayout->addWidget(lastReadLabel); mainLayout->addWidget(lastReadValueLabel); mainLayout->addWidget(lastModLabel); mainLayout->addWidget(lastModValueLabel); mainLayout->addStretch(1); setLayout(mainLayout); } PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions")); QCheckBox *readable = new QCheckBox(tr("Readable")); if (fileInfo.isReadable()) readable->setChecked(true); QCheckBox *writable = new QCheckBox(tr("Writable")); if ( fileInfo.isWritable() ) writable->setChecked(true); QCheckBox *executable = new QCheckBox(tr("Executable")); if ( fileInfo.isExecutable() ) executable->setChecked(true); QGroupBox *ownerGroup = new QGroupBox(tr("Ownership")); QLabel *ownerLabel = new QLabel(tr("Owner")); QLabel *ownerValueLabel = new QLabel(fileInfo.owner()); ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *groupLabel = new QLabel(tr("Group")); QLabel *groupValueLabel = new QLabel(fileInfo.group()); groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QVBoxLayout *permissionsLayout = new QVBoxLayout; permissionsLayout->addWidget(readable); permissionsLayout->addWidget(writable); permissionsLayout->addWidget(executable); permissionsGroup->setLayout(permissionsLayout); QVBoxLayout *ownerLayout = new QVBoxLayout; ownerLayout->addWidget(ownerLabel); ownerLayout->addWidget(ownerValueLabel); ownerLayout->addWidget(groupLabel); ownerLayout->addWidget(groupValueLabel); ownerGroup->setLayout(ownerLayout); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(permissionsGroup); mainLayout->addWidget(ownerGroup); mainLayout->addStretch(1); setLayout(mainLayout); } ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QLabel *topLabel = new QLabel(tr("Open with:")); QListWidget *applicationsListBox = new QListWidget; QStringList applications; for (int i = 1; i <= 30; ++i) applications.append(tr("Application %1").arg(i)); applicationsListBox->insertItems(0, applications); QCheckBox *alwaysCheckBox; if (fileInfo.suffix().isEmpty()) alwaysCheckBox = new QCheckBox(tr("Always use this application to " "open this type of file")); else alwaysCheckBox = new QCheckBox(tr("Always use this application to " "open files with the extension '%1'").arg(fileInfo.suffix())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(topLabel); layout->addWidget(applicationsListBox); layout->addWidget(alwaysCheckBox); setLayout(layout); }
图形:
当没有给main传参数的时候,argv中只有一个值,就是可执行的exe QT中传参数的方法见上图。
相关文章推荐
- Qt学习(2)
- QT自定义控件
- Qt 添加程序运行图标
- Qt学习(1)
- QT creator 3.4.1配置arm交叉编译环境(QT5.4.2)
- pyqt py文件中引用多个界面
- Ubuntu下Qt Creator中完成第一个OpenCV程序
- Qt 创建状态栏
- 认识QT ----- 多窗口以及窗口之间的传值
- Ubuntu14.04 安装Qt5.2.1
- qt_简易记事本_5
- Qt - 正确判断文件、文件夹是否存在的方法
- QT中PRO文件写法的详细介绍
- qt_简易记事本_4
- Qt的Window Close与程序退出
- QT开发
- PyQt5教程(三)——布局管理
- win10下qt 中没有代码提示框了怎么办?
- Qt中MainWindow类实例
- Qt 创建工具栏