1、堆栈窗体的使用
stack.h
#ifndef STACK_H
#define STACK_H
#include
class StackDlg:public QDialog
{
Q_OBJECT
public:
StackDlg(QWidget *parent=0,Qt::WindowFlags f1=0);
QLabel *label1;
QLabel *label2;
QLabel *label3;
QListWidget *list;
QStackedWidget *stack;
};
#endif
stack.cpp
#include "stack.h"
StackDlg::StackDlg(QWidget *parent,Qt::WindowFlags f1)
:QDialog(parent,f1)
{
setWindowTitle(tr("stack widigets"));
list=new QListWidget(this);
list->insertItem(0,tr("Window1"));
list->insertItem(1,tr("Window2"));
list->insertItem(2,tr("Window3"));
label1=new QLabel(tr("This is Window1!"));
label2=new QLabel(tr("This is Window2!"));
label3=new QLabel(tr("This is Window3!"));
stack=new QStackedWidget(this);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
QHBoxLayout *mainLayout=new QHBoxLayout(this);
mainLayout->setMargin(4);
mainLayout->setSpacing(4);
mainLayout->addWidget(list);
mainLayout->addWidget(stack,0,Qt::AlignHCenter);
mainLayout->setStretchFactor(list,1);
mainLayout->setStretchFactor(stack,3);
connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
}
main.cpp
#include
#include
int main(int argc,char *argv[])
{
//QFont font("ZYSong18030",8);
// QApplication::setFont(font);
QApplication a(argc,argv);
QTranslator translator(0);
translator.load("stack_zh",".");
a.installTranslator(&translator);
StackDlg stack;
stack.show();
return a.exec();
}
阅读(1686) | 评论(0) | 转发(0) |