QToolBox简单使用

用QToolBox模仿qq好友菜单
QToolBox简单使用
头文件:

#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()
{

}

上一篇:【DB笔试面试677】在Oracle中,对于一个NUMBER(1)的列,若WHERE条件是大于3和大于等于4,这二者是否等价?...


下一篇:集成学习-Bagging集成学习算法随机森林(Random Forest)