Most likely you didn't set a layout somewhere. And use QStackedWidget instead of QMainWindow, you don't need one.
Ok, I created a new Qt class on the project which is
class StackedWidget : public QStackedWidget
To copy to clipboard, switch view to plain text mode
and I copied the same code I had in Mainwindow to its constructor, so I have:
StackedWidget
::StackedWidget(QWidget *parent
) : ui(new Ui::StackedWidget)
{
ui->setupUi(this);
addWidget(new WP1);
setFixedSize(480,300);
m_pComboBox->addItem("Page 1");
m_pComboBox->addItem("Page 2");
m_pComboBox->addItem("Page 3");
layout->addWidget(m_pComboBox);
setWindowTitle("QStackedWidget Change CurrentIndex");
centralWidget->setLayout(layout);
setFixedSize(500,350);
connect(m_pComboBox,SIGNAL(activated(int)),this,SLOT(setCurrentIndex(int)));
}
StackedWidget::StackedWidget(QWidget *parent) :
QStackedWidget(parent),
ui(new Ui::StackedWidget)
{
ui->setupUi(this);
QWidget* centralWidget = new QWidget();
QComboBox *m_pComboBox = new QComboBox();
addWidget(new WP1);
addWidget(new QPushButton("Button 3"));
addWidget(new QPushButton("Button 2"));
setFixedSize(480,300);
m_pComboBox->addItem("Page 1");
m_pComboBox->addItem("Page 2");
m_pComboBox->addItem("Page 3");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_pComboBox);
setWindowTitle("QStackedWidget Change CurrentIndex");
centralWidget->setLayout(layout);
setFixedSize(500,350);
connect(m_pComboBox,SIGNAL(activated(int)),this,SLOT(setCurrentIndex(int)));
}
To copy to clipboard, switch view to plain text mode
But it shows nothings more than an empty window
And in main.cpp :
StackedWidget st;
st.setFixedSize(960,600);
st.show();
StackedWidget st;
st.setFixedSize(960,600);
st.show();
To copy to clipboard, switch view to plain text mode
Bookmarks