Qt应用开发(基础篇)——工具箱 QToolBox

一、前言

        QToolBox类继承于QFrame,QFrame继承于QWidget,是Qt常用的基础工具部件。

        框架类QFrame介绍

        QToolBox工具箱类提供了一列选项卡窗口,当前项显示在当前选项卡下面,适用于分类浏览内容展示操作指引这一类的使用场景。

二、QToolBox类

1、count

        该属性表示当前工具箱选项卡的数量。

int count() const    //获取选项卡数

2、currentIndex

        该属性表示当前显示选项卡的下标,如果选项卡数量为0,则返回-1。

int currentIndex() const            //获取当前选项卡下标
void setCurrentIndex(int index)     //设置当前选项卡下标

3、公共方法

1)增加选项卡

        使用addItem在尾部插入选项卡。

int addItem(QWidget *widget, const QIcon &iconSet, const QString &text)
int addItem(QWidget *w, const QString &text)
2)插入选项卡

        使用InsertItem在任意位置插入选项卡,如果索引index超出范围,那么插入到尾部。

int insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text)
int insertItem(int index, QWidget *widget, const QString &text)
3)移除选项卡

        使用removeItem移除目标下标的选项卡,这里是从工具箱中移除,而不是删除部件。

void removeItem(int index)
4)设置/获取选项卡图标
QIcon itemIcon(int index) const
void setItemIcon(int index, const QIcon &icon)
5)设置/读取选项卡文本
QString itemText(int index) const
void setItemText(int index, const QString &text)
6)设置/读取选项卡提示文本
QString itemToolTip(int index) const
void setItemToolTip(int index, const QString &toolTip)
7)设置/读取选项卡显示项
QWidget *widget(int index) const
QWidget *currentWidget() const
void setCurrentWidget(QWidget *widget)
8)设置/读取选项卡使能
bool isItemEnabled(int index) const
void setItemEnabled(int index, bool enabled)
9)查找选项卡

        使用indexOf查找某选项卡的索引,如果不存在则返回-1。

int indexOf(QWidget *widget) const

4、信号

        当前选项卡改变的时候触发信号。

void currentChanged(int index)

5、示例

QLabel *lab1 = new QLabel("大话西游");
QLabel *lab2 = new QLabel("整蛊专家");
QLabel *lab3 = new QLabel("功夫");
QWidget *widget1 = new QWidget();
QVBoxLayout *lay1 = new QVBoxLayout();

lay1->addWidget(lab1);
lay1->addWidget(lab2);
lay1->addWidget(lab3);
widget1->setLayout(lay1);
tool->addItem(widget1,"周星驰");

QLabel *lab4 = new QLabel("寒战");
tool->addItem(lab4,"刘德华");

QLabel *lab5 = new QLabel("赌神");
tool->addItem(lab5,"周润发");

执行结果:

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

波塞冬~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值