A multi-page switching components
A.Qt in multi-page switching components QTabWidget
1. content can freely switch between different pages in the same window
2 is a type of container components, while providing friendly page switching mode
QTabWidget of use
1. Create the application QTabWidget object
2. QWidget other objects added to the object
implementation
1. Create a class object container assembly
2. the plurality of sub-component layout in a container object
3. the object is added to the vessel to generate a new page QTabWidget
QTabWidget assembly substantially usage
advanced usage B.QTabWidget assembly
1. the installation position of the label tab
2. tab disposed appearance
3. tab setting off mode of
QTabWidget assembly predefined signal
void currentChange (int index) - the currently displayed page transmission change, index of new page index
void tabCloseRequsted (int index) - clicked position close request is issued the Close button page index
code sample
Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTableWidget>
class Widget : public QWidget
{
Q_OBJECT
QTabWidget m_tabWidget;
protected slots:
void onTabCurrentChanged(int index);
void onTabCloseRequested(int index);
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
Widget.cpp
#include "Widget.h"
#include <QPlainTextEdit>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//QTabWidget的基本设置
m_tabWidget.setParent(this);
m_tabWidget.move(10, 10);
m_tabWidget.resize(200, 200);
m_tabWidget.setTabPosition(QTabWidget::North);
m_tabWidget.setTabShape(QTabWidget::Triangular);
m_tabWidget.setTabsClosable(false);
QPlainTextEdit* edit = new QPlainTextEdit(&m_tabWidget);
edit->insertPlainText("页面1");
m_tabWidget.addTab(edit, "1st");
QWidget* widget = new QWidget(&m_tabWidget);
QVBoxLayout* layout = new QVBoxLayout();
QLabel* lbl = new QLabel(widget);
QPushButton* btn = new QPushButton(widget);
lbl->setText("页面2");
lbl->setAlignment(Qt::AlignCenter);
btn->setText("页面2");
layout->addWidget(lbl);
layout->addWidget(btn);
widget->setLayout(layout);
m_tabWidget.addTab(widget, "2nd");
m_tabWidget.setCurrentIndex(1);
connect(&m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabCurrentChanged(int)));
connect(&m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(onTabCloseRequested(int)));
}
void Widget::onTabCurrentChanged(int index)
{
qDebug() << "Page change to: " << index;
}
void Widget::onTabCloseRequested(int index)
{
m_tabWidget.removeTab(index);
}
Widget::~Widget()
{
}
Operating results shown in FIG.