#ifndef DIALOG_H
#define DIALOG_H
#include
#include
#include
#include
class StackDialog : public QDialog
{
Q_OBJECT
public:
StackDialog(QWidget *parent = 0);
~StackDialog();
private:
QListWidget *list;
QStackedWidget *stack;
QLabel *label1;
QLabel *label2;
QLabel *label3;
};
#endif // DIALOG_H
#include "stackDialog.h"
#include
#include
StackDialog::StackDialog(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("妞 给爷笑一个")); list = new QListWidget(this);//列表控件 list->insertItem(0,tr("淑女")); list->insertItem(0,tr("萝莉")); list->insertItem(0,tr("少妇")); label1 = new QLabel(tr("淑女")); label2 = new QLabel(tr("萝莉")); label3 = new QLabel(tr("少妇")); QPixmap p(300,400); p.load(":/26.JPG"); p.scaled(0.2,0.2); label2->setPixmap(p); stack = new QStackedWidget(this); stack->addWidget(label1); stack->addWidget(label2); stack->addWidget(label3); QHBoxLayout *layout =new QHBoxLayout(this); layout->setMargin(5); layout->setSpacing(5); layout->addWidget(list); layout->addWidget(stack,0,Qt::AlignCenter); layout->setStretchFactor(list,1); layout->setStretchFactor(stack,3); connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int))); } StackDialog::~StackDialog() { }#include "stackDialog.h" #include
int main(int argc, char *argv[]) { QApplication a(argc, argv); StackDialog w; w.show(); return a.exec(); }