由于界面上的图标比较多的话就必须加滚动了
#ifndef STATE1_H
#define STATE1_H
#include <QWidget>
#include "mytoolbutton.h"
class QToolButton;
class QFrame;
class QScrollArea;
class QGridLayout;
class State1_Main : public QWidget
{
Q_OBJECT
public:
explicit State1_Main(QWidget *parent = 0);
virtual ~State1_Main();
void translatestring_state1();
signals:
public slots:
private:
QToolButton *toolbutton1;
QToolButton *toolbutton2;
QToolButton *toolbutton3;
QToolButton *toolbutton4;
QToolButton *toolbutton5;
QToolButton *toolbutton6;
QToolButton *toolbutton7;
QToolButton *toolbutton8;
QToolButton *toolbutton9;
QToolButton *toolbutton10;
QToolButton *toolbutton11;
QToolButton *toolbutton12;
QScrollArea* scroll;
QFrame *frame;
QGridLayout *layout;
void createbuttons(void);
};
#endif // STATE1_H
#include "state1_main.h".h"
#include <QtGui>
State1_Main::State1_Main(QWidget *parent) :
QWidget(parent)
{
scroll = new QScrollArea(0);
frame = new QFrame(scroll);
scroll->setWidget(frame);
scroll->setWidgetResizable(true);
layout = new QGridLayout(frame);
frame->setLayout(layout);
createbuttons();
scroll->show();
QVBoxLayout *mainlayout=new QVBoxLayout;
mainlayout->addWidget(scroll);
this->setLayout(mainlayout);
this->setFixedSize(480,560);
}
State1_Main::~State1_Main()
{
}
void State1_Main::translatestring_state1()
{
}
void State1_Main::createbuttons(void)
{
int row,colum;
for (int i=0; i<40; i++)
{
row=i/4;
colum=i%4;
MytoolButton *toolbutton=new MytoolButton;
toolbutton->setText("state 1");
toolbutton->setIcon(QIcon("/home/user/Qt/pic/navi_uzone.png"));
layout->addWidget(toolbutton,row,colum);
}
}