QToolBox简单使用
作者:互联网
用QToolBox模仿qq好友菜单
头文件:
#ifndef MYQQ_H
#define MYQQ_H
#include<QToolBox>
#include<QToolButton>
class MyQQ : public QToolBox
{
Q_OBJECT
public:
MyQQ(QWidget *parent = 0);
~MyQQ();
private:
QToolButton *num1;
QToolButton *num2;
QToolButton *num3;
QToolButton *num4;
QToolButton *num5;
QToolButton *num6;
};
#endif // MYQQ_H
源文件:
#include "myqq.h"
#include<QPixmap>
#include<QGroupBox>
#include<QHBoxLayout>
MyQQ::MyQQ(QWidget *parent)
: QToolBox(parent)
{
this->setWindowTitle("QQ");
num1=new QToolButton;
num1->setText("张三");
num1->setIcon(QPixmap(":/Luffy.png"));
num1->setIconSize(QPixmap(":/Luffy.png").size());
num1->setAutoRaise(true);//放开按钮恢复
num1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
num2=new QToolButton;
num2->setText("李四");
num2->setIcon(QPixmap(":/Luffy.png"));
num2->setIconSize(QPixmap(":/Luffy.png").size());
num2->setAutoRaise(true);//放开按钮恢复
num2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QGroupBox *myfriendbox=new QGroupBox;
QHBoxLayout *myfriendlayout=new QHBoxLayout(myfriendbox);
myfriendlayout->setMargin(10);
myfriendlayout->addWidget(num1);
myfriendlayout->addWidget(num2);
num3=new QToolButton;
num3->setText("王五");
num3->setIcon(QPixmap(":/Luffy.png"));
num3->setIconSize(QPixmap(":/Luffy.png").size());
num3->setAutoRaise(true);//放开按钮恢复
num3->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
num4=new QToolButton;
num4->setText("六六");
num4->setIcon(QPixmap(":/Luffy.png"));
num4->setIconSize(QPixmap(":/Luffy.png").size());
num4->setAutoRaise(true);//放开按钮恢复
num4->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QGroupBox *mystranger=new QGroupBox;
QVBoxLayout *strangerlayout=new QVBoxLayout(mystranger);
strangerlayout->setMargin(10);
strangerlayout->addWidget(num3);
strangerlayout->addWidget(num4);
num5=new QToolButton;
num5->setText("七七");
num5->setIcon(QPixmap(":/Luffy.png"));
num5->setIconSize(QPixmap(":/Luffy.png").size());
num5->setAutoRaise(true);//放开按钮恢复
num5->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
num6=new QToolButton;
num6->setText("八八");
num6->setIcon(QPixmap(":/Luffy.png"));
num6->setIconSize(QPixmap(":/Luffy.png").size());
num6->setAutoRaise(true);//放开按钮恢复
num6->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QGroupBox *myhei=new QGroupBox;
QVBoxLayout *heilayout=new QVBoxLayout(myhei);
heilayout->setMargin(10);
heilayout->addWidget(num5);
heilayout->addWidget(num6);
this->addItem(myfriendbox,"我的好友");
this->addItem(mystranger,"我的陌生人");
this->addItem(myhei,"我的黑名单");
}
MyQQ::~MyQQ()
{
}
标签:num4,QToolButton,简单,QToolBox,使用,new,Luffy,QPixmap,png 来源: https://blog.csdn.net/weixin_47414687/article/details/115603917