Detailed explanation of the use of QT QToolBox control

        This article introduces various operations of the QToolBox control in detail, such as: create a new interface , add a tab , index the current item , get the index of the current item , get the current item window , get the window whose index value is int, and remove the index value item , Get the number of items, get the specified index value, set whether the index item is activated, get the index value item is activated, set the icon of the item, get the icon of the item, set the title name of the item, get the title name of the item, set the prompt information of the item, get Item prompt information, setting the currently displayed tab, signal slot, source code , other articles, etc.

        In actual development, an interface may contain more than a dozen controls, and manually adjusting their positions is time-consuming and laborious. The QToolBox class provides a list of tabbed widget items. The toolbox control QToolBox is somewhat similar to the switching card control QTableWidget, and it also consists of multiple pages, and each page has a title name. It is suitable for usage scenarios such as category browsing, content display, and operation guidance.

        There are currently 33 articles in this series of QT comprehensive and detailed articles. This series of articles describes the basic operation and use of QT controls in more detail. Thank you for your attention, likes, and collections.
 

 The author of this article is original, please attach the source of the article and the link of this article for reprinting.

QT QToolBox control use detailed directory

1 New interface

2 Add tab

3 index set current item

4 Get the index of the current item

5 Get current item window

6 Get the window whose index value is int

7 Remove the index value item

8 Get the number of items

9 Get the specified index value

10 Set whether the index item is activated

11 Get whether the index value item is activated

12 Icons for setting items

13 Get the icon of the item

14 Setting item title name

15 Get item title name

16 Setting item prompt information

17 Obtain item prompt information

18 Set the currently displayed tab

19 signal slots

20 source code

21 Other articles


1 New interface

2 Add tab

    // 添加页签 QIcon图标或QPixmap图像
    //QIcon icon("");
    //QWidget* widget1 = new QWidget;
    //QWidget* widget2 = new QWidget;
    //QWidget* widget3 = new QWidget;
    //ui->toolBox->addItem(new widget1, "D:/a.png", "Page 0");
    //ui->toolBox->addItem(new widget2, QIcon(), "Page 1");
    //ui->toolBox->addItem(new widget3, QIcon(), "Page 2");
    //ui->toolBox->addItem(new QLabel("Content for page 3"), QIcon(), "Page 3");

    //根据索引插入项,新插入项的索引值是index
    //ui->toolBox->insertItem(3,widget1,icon,"");
    //ui->toolBox->insertItem(3,widget1,"D:/a.png","");

3 index set current item

ui->toolBox->setCurrentIndex(2);

4 Get the index of the current item

qDebug() << "当前索引" << ui->toolBox->currentIndex();

5 Get current item window

ui->toolBox->currentWidget();

6 Get the window whose index value is int

ui->toolBox->widget(2);

7 Remove the index value item

ui->toolBox->removeItem(2);

8 Get the number of items

ui->toolBox->count();

9 Get the specified index value

ui->toolBox->indexOf(ui->page_3);

10 Set whether the index item is activated

ui->toolBox->setItemEnabled(2,true);

11 Get whether the index value item is activated

ui->toolBox->isItemEnabled(0);

12 Icons for setting items

ui->toolBox->setItemIcon(0,icon);

13 Get the icon of the item

ui->toolBox->itemIcon(0);

14 Setting item title name

ui->toolBox->setItemText(0,"page 1");

15 Get item title name

ui->toolBox->itemIcon(0);

16 Setting item prompt information

ui->toolBox->setItemToolTip(0,"提示");

17 Obtain item prompt information

ui->toolBox->itemToolTip(0);

18 Set the currently displayed tab

ui->toolBox->setCurrentWidget(ui->widget3);

19 signal slots

private slots:
    void on_toolBox_currentChanged(int index);

connect(ui->toolBox, &QToolBox::currentChanged, this, &MainWindow::on_toolBox_currentChanged);

void MainWindow::on_toolBox_currentChanged(int index)
{
    qDebug() << "Current page changed: " << index;
}

20 source code

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>

//加入GBK申明,否则中文乱码 全局使用GBK文件操作因为有中文所以使用
#pragma execution_character_set("utf-8")

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_toolBox_currentChanged(int index);
private:
    Ui::MainWindow *ui;

    QString Title;
    QString Version;
    QString BlogText;

    QWidget mWidget;
};
#endif // MAINWINDOW_H

21 Other articles

QT TextEdit Control_Gemini Breakpoint Blog-CSDN Blog_qt textedit

Detailed explanation of the use of QT QComboBox - Gemini Breakpoint Blog - CSDN Blog

Detailed explanation of QT QtableView operation

Qt QStandardItemModel (1. Super detailed usage)_ Gemini Breakpoint Blog-CSDN Blog_qstandardmodel

Qt QStandardItemModel (2. Super detailed function)_Gemini breakpoint blog-CSDN blog_qstandarditemmodel click event

Detailed use of QT QRadioButton - Gemini Breakpoint Blog - CSDN Blog - qt radiobutton

Detailed use of QT QLineEdit_ Gemini Breakpoint Blog-CSDN Blog_qt qlineedit

Detailed explanation of Qt QMessageBox use - Gemini Breakpoint Blog - CSDN Blog - qt message

QChart Line Chart, Pie Chart, Bar Chart, Curve Chart_ Gemini Breakpoint Blog-CSDN Blog_qchart Style

Detailed explanation of QChart properties_ Gemini Breakpoint Blog-CSDN Blog_setanimationoptions

Use of QCharts QValueAxis_Gemini Breakpoint Blog-CSDN Blog_qvalueaxis

Qt 5 wait prompt box (open source dynamic graph)_ Gemini Breakpoint Blog-CSDN Blog_qt wait dialog box

QtDataVisualization Data 3D Visualization_Gemini Breakpoint Blog-CSDN Blog_qtdatavisualizatio

QT QSpinBox Integer Counter Control Use Detailed Explanation_Gemini Breakpoint Blog-CSDN BlogQT
QDoubleSpinBox Floating Point Counter Control (Detailed Use)_Gemini Breakpoint Blog-CSDN Blog_qdoublespinbox Signal Slot
QT QSlider, QHorizontalSlider, QVerticalSlider Control Use Detailed Explanation_Gemini Breakpoint blog-CSDN blog_qslider set step size

Detailed explanation of the use of QT QTabWidget control - Gemini Breakpoint Blog - CSDN Blog

Detailed explanation of the use of QT QCalendarWidget control - Gemini Breakpoint Blog - CSDN Blog

Detailed use of QT QStackedWidget control - Gemini Breakpoint Blog - CSDN Blog

QT QVBoxLayout vertical layout control - Gemini Breakpoint Blog - CSDN Blog

QT QHBoxLayout Horizontal Layout Control_Gemini Breakpoint Blog-CSDN BlogQT
QGridLayout Grid Layout Control_Gemini Breakpoint Blog-CSDN Blog

QT QVerticalSpacer Spring Control_Gemini Breakpoint Blog-CSDN BlogQT
QHorizontalSpacer Spring Control_Gemini Breakpoint Blog-CSDN BlogQT
QLine Use Detailed Explanation_Gemini Breakpoint Blog-CSDN Blog

Detailed explanation of QT QFontComboBox use - Gemini Breakpoint Blog - CSDN Blog

Guess you like

Origin blog.csdn.net/qq_37529913/article/details/132682424