Qt工具盒

//drawer.h

#ifndef DRAWER_H
#define DRAWER_H
#include 
#include 

class Drawer : public QToolBox
{
public:
    Drawer();
private:
    QToolButton *toolBtn1_1;
    QToolButton *toolBtn1_2;
    QToolButton *toolBtn1_3;
    QToolButton *toolBtn1_4;
    QToolButton *toolBtn1_5;
    QToolButton *toolBtn2_1;
    QToolButton *toolBtn2_2;
    QToolButton *toolBtn3_1;
    QToolButton *toolBtn3_2;
};

#endif // DRAWER_H

//drawer.cpp

#include "drawer.h"
#include 
#include 

Drawer::Drawer()
{
    setWindowTitle(tr("My QQ"));

    toolBtn1_1 = new QToolButton;
    toolBtn1_1->setText(tr("张1"));
    //图片路径容易错
    toolBtn1_1->setIcon(QPixmap("D:/file/110.PNG"));
    //图片大小,注意要有值
    toolBtn1_1->setIconSize(QSize(30, 30));
    toolBtn1_1->setAutoRaise(true);
    toolBtn1_1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn1_2 = new QToolButton;
    toolBtn1_2->setText(tr("张2"));
    toolBtn1_2->setIcon(QPixmap("D:/file/110.PNG"));
    toolBtn1_2->setIconSize(QPixmap("D:/file/110.PNG").size());
    toolBtn1_2->setAutoRaise(true);
    toolBtn1_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn1_3 = new QToolButton;
    toolBtn1_3->setText(tr("张3"));
    toolBtn1_3->setIcon(QPixmap("./0.jpg"));
    toolBtn1_3->setIconSize(QPixmap("./0.jpg").size());

    toolBtn1_3->setAutoRaise(true);
    toolBtn1_3->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn1_4 = new QToolButton;
    toolBtn1_4->setText(tr("张44"));
    toolBtn1_4->setIcon(QPixmap("./0.jpg"));
    toolBtn1_4->setIconSize(QPixmap("./0.jpg").size());
    toolBtn1_4->setAutoRaise(true);
    toolBtn1_4->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn1_5 = new QToolButton;
    toolBtn1_5->setText(tr("张5"));
    toolBtn1_5->setIcon(QPixmap("./0.jpg"));
    toolBtn1_5->setIconSize(QPixmap("./0.jpg").size());
    toolBtn1_5->setAutoRaise(true);
    toolBtn1_5->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    QGroupBox *groupBox1 = new QGroupBox;
    QVBoxLayout *vbLayout1 = new QVBoxLayout(groupBox1);
    vbLayout1->setMargin(10);
    vbLayout1->setAlignment(Qt::AlignHCenter);

    vbLayout1->addWidget(toolBtn1_1);
    vbLayout1->addWidget(toolBtn1_2);
    vbLayout1->addWidget(toolBtn1_3);
    vbLayout1->addWidget(toolBtn1_4);
    vbLayout1->addWidget(toolBtn1_5);

    vbLayout1->addStretch();

    toolBtn2_1 = new QToolButton;
    toolBtn2_1->setText(tr("张1"));
    toolBtn2_1->setIcon(QPixmap("./0.jpg"));
    toolBtn2_1->setIconSize(QPixmap("./0.jpg").size());
    toolBtn2_1->setAutoRaise(true);
    toolBtn2_1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn2_2 = new QToolButton;
    toolBtn2_2->setText(tr("张2"));
    toolBtn2_2->setIcon(QPixmap("./0.jpg"));
    toolBtn2_2->setIconSize(QPixmap("./0.jpg").size());
    toolBtn2_2->setAutoRaise(true);
    toolBtn2_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    QGroupBox *groupBox2 = new QGroupBox;
    QVBoxLayout *vbLayout2 = new QVBoxLayout(groupBox2);
    vbLayout2->setMargin(10);
    vbLayout2->setAlignment(Qt::AlignHCenter);

    vbLayout2->addWidget(toolBtn2_1);
    vbLayout2->addWidget(toolBtn2_2);

    toolBtn3_1 = new QToolButton;
    toolBtn3_1->setText(tr("张1"));
    toolBtn3_1->setIcon(QPixmap("./0.jpg"));
    toolBtn3_1->setIconSize(QPixmap("./0.jpg").size());
    toolBtn3_1->setAutoRaise(true);
    toolBtn3_1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    toolBtn3_2 = new QToolButton;
    toolBtn3_2->setText(tr("张2"));
    toolBtn3_2->setIcon(QPixmap("./0.jpg"));
    toolBtn3_2->setIconSize(QPixmap("./0.jpg").size());
    toolBtn3_2->setAutoRaise(true);
    toolBtn3_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    QGroupBox *groupBox3 = new QGroupBox;
    QVBoxLayout *vbLayout3 = new QVBoxLayout(groupBox3);
    vbLayout3->setMargin(10);
    vbLayout3->setAlignment(Qt::AlignHCenter);

    vbLayout3->addWidget(toolBtn3_1);
    vbLayout3->addWidget(toolBtn3_2);

    this->addItem((QWidget*)groupBox1,tr("我的好友"));
    this->addItem((QWidget*)groupBox2,tr("陌生人"));
    this->addItem((QWidget*)groupBox3,tr("黑名单"));
}

//main.cpp

#include "drawer.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Drawer drawer;
    drawer.show();

    return a.exec();
}

 

你可能感兴趣的:(QT,对话框)