Qt高手请进,有关QStackedWidget问题#include dialog.h#includeQLabel#includeQStackedWidget#includ
Qt高手请进,有关QStackedWidget问题
#include "dialog.h"
#include<QLabel>
#include<QStackedWidget>
#include<QListWidget>
#include<QHBoxLayout>
#include<QWidget>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
QWidget *widget1=new QWidget(this);
QWidget *widget2=new QWidget(this);
QLabel *label1=new QLabel(widget1);
QLabel *label2=new QLabel(widget2);
label1->setText("the first page");
label2->setText("the second page");
QStackedWidget *stack=new QStackedWidget;
QListWidget *list=new QListWidget;
list->insertItem(0,"first");
list->insertItem(1,"second");
stack->addWidget(widget1);
stack->addWidget(widget2);
widget1->show();
widget2->show();
QHBoxLayout *layout=new QHBoxLayout(this);
layout->setMargin(5);
layout->addWidget(list,1);
layout->addWidget(stack,2,Qt::AlignHCenter);
layout->setSpacing(5);
connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
stack->setCurrentIndex(1);
this->resize(500,400);
}
Dialog::~Dialog()
{
}
我想问为什么运行后widget1显示不出来,希望高手能够解答,请高手把上面代码运行一次后才告诉我问题出在哪里,因为我的可用分有限,不能经常发帖,我是菜鸟来的,请高手多多包涵。
[最优解释]出来了啊。。。我这儿就出来了。。
#include "dialog.h"
#include "ui_dialog.h"
#include<QLabel>
#include<QStackedWidget>
#include<QListWidget>
#include<QHBoxLayout>
#include<QWidget>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QWidget *widget1=new QWidget(this);
QWidget *widget2=new QWidget(this);
QLabel *label1=new QLabel(widget1);
QLabel *label2=new QLabel(widget2);
label1->setText("the first page");
label2->setText("the second page");
QStackedWidget *stack=new QStackedWidget;
QListWidget *list=new QListWidget;
list->insertItem(0,"first");
list->insertItem(1,"second");
stack->addWidget(widget1);
stack->addWidget(widget2);
widget1->show();
widget2->show();
QHBoxLayout *layout=new QHBoxLayout(this);
layout->setMargin(5);
layout->addWidget(list);
layout->addWidget(stack);
layout->setSpacing(5);
connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
stack->setCurrentIndex(1);
this->resize(500,400);
}
Dialog::~Dialog()
{
delete ui;
}
[其他解释]
// layout->addWidget(list,1);
// layout->addWidget(stack,2,Qt::AlignHCenter);
layout->addWidget(list);
layout->addWidget(stack);
这样就出来了。
[其他解释]
高手,求帮忙啊!!!
[其他解释]高手,求邮箱,我有个demo运行不了,我想发给你看看出了问题。
[其他解释]高手,求帮助啊!!!