Qt basic learning (6)-qtabwidget for multi-page Switching

Source: Internet
Author: User
 //mydialog.h#ifndef MYDIALOG_H#define MYDIALOG_H#include <QDialog>class QTabWidget;class MyDialog : public QDialog{  Q_OBJECTpublic:  explicit MyDialog(QWidget *parent = 0);signals:public slots:private:  QTabWidget *tabWidget;};#endif // MYDIALOG_H

 

// Mydialog. CPP # include "mydialog. H "# include <qtgui/qtabwidget> # include <qtgui/qhboxlayout> # include <qtgui/qvboxlayout> # include <qtgui/qlabel> # include <qtgui/qlineedit> # include <qtgui/qpushbutton> # include <qtgui/qwidget> # include <qtgui/qicon> mydialog:: mydialog (qwidget * parent): qdialog (parent) {tabwidget = new qtabwidget (); // create a component qwidget * widget = new qwidget () on the first page (); qlineedit * lineedit = new qlineedit (); qpushbutton * Pushbutton = new qpushbutton ("test"); Comment * vlayout = new qvboxlayout (); vlayout-> addwidget (lineedit ); vlayout-> addwidget (Pushbutton); widget-> setlayout (vlayout); // create a component qlabel * label = new qlabel ("Hello QT") on the second page "); // create the third page component qpushbutton * pushbutton3 = new qpushbutton ("Click me"); // Add the first page qicon icon1 (": /New/icon/images/1.ico"); tabwidget-> addtab (widget, icon1, "tab1"); // Add qicon icon2 (": /New/icon/images/2.ico"); tabwidget-> addtab (Label, icon2, "tab2"); // Add the third page qicon icon3 (": /New/icon/images/3.ico"); tabwidget-> addtab (pushbutton3, icon3, "tab3"); qhboxlayout * layout = new qhboxlayout (); layout-> addwidget (tabwidget); this-> setlayout (layout); this-> resize (300,100); this-> setwindowtitle ("qtabwidgetdemo ");}

 

//main.cpp#include <QtGui/QApplication>#include "mydialog.h"int main(int argc, char *argv[]){  QApplication a(argc, argv);  MyDialog dialog;  dialog.show();  return a.exec();}

 

Resource file:

 

Program running:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.