Qt中QTabWidget使用

转载自https://blog.csdn.net/qiurisuixiang/article/details/6916603


   
   
   
   
  1. //mydialog.h
  2. #ifndef MYDIALOG_H
  3. #define MYDIALOG_H
  4. #include
  5. class QTabWidget;
  6. class MyDialog : public QDialog
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit MyDialog(QWidget *parent = 0);
  11. signals:
  12. public slots:
  13. private:
  14. QTabWidget *tabWidget;
  15. };
  16. #endif // MYDIALOG_H


 


   
   
   
   
  1. //mydialog.cpp
  2. #include "mydialog.h"
  3. #include
  4. #include
  5. #include
  6. #include
  7. #include
  8. #include
  9. #include
  10. #include
  11. MyDialog::MyDialog(QWidget *parent) :
  12. QDialog(parent)
  13. {
  14. tabWidget = new QTabWidget();
  15. //新建第一个页面的部件
  16. QWidget *widget = new QWidget();
  17. QLineEdit *lineEdit = new QLineEdit();
  18. QPushButton *pushButton = new QPushButton( "Test");
  19. QVBoxLayout *vLayout = new QVBoxLayout();
  20. vLayout->addWidget(lineEdit);
  21. vLayout->addWidget(pushButton);
  22. widget->setLayout(vLayout);
  23. //新建第二个页面的部件
  24. QLabel *label = new QLabel( "Hello Qt");
  25. //新建第三个页面的部件
  26. QPushButton *pushButton3 = new QPushButton( "Click Me");
  27. //向QTabWidget中添加第一个页面
  28. QIcon icon1(":/new/icon/images/1.ico");
  29. tabWidget->addTab(widget, icon1, "Tab1");
  30. //向QTabWidget中添加第二个页面
  31. QIcon icon2(":/new/icon/images/2.ico");
  32. tabWidget->addTab(label, icon2, "Tab2");
  33. //向QTabWidget中添加第三个页面
  34. QIcon icon3(":/new/icon/images/3.ico");
  35. tabWidget->addTab(pushButton3, icon3, "Tab3");
  36. QHBoxLayout *layout = new QHBoxLayout();
  37. layout->addWidget(tabWidget);
  38. this->setLayout(layout);
  39. this->resize( 300, 100);
  40. this->setWindowTitle( "QTabWidgetDemo");
  41. }


 


   
   
   
   
  1. //main.cpp
  2. #include
  3. #include "mydialog.h"
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MyDialog dialog;
  8. dialog.show();
  9. return a.exec();
  10. }


 

资源文件截图:

 

程序运行截图:

 

你可能感兴趣的:(Qt中QTabWidget使用)