View Full Version : UI implementation style

14th August 2007, 11:33
Requesting advice for QStackedWidget, QMainWindow program I am trying to get going.

I have a Qt Designer UI which contains a QStackedWidget in a QMainWindow, with a toolbar above the stackedWidget (fairly straightforward). I would like to create separate classes which represent each page of the stackedWidget (for manageability).

Since Designer has one file for the whole GUI how would I put the whole thing together? I was thinking something like the following:
mainWindow.h & .cpp (construct the gui and implement toolbar buttons to change pages on the qstackedwidget)
page1.h & .cpp (exclusively control page 1)
page2 ..... and so on.

First, does this sound like a good plan?
Second, pretty sure I would #include the ui_UIfilename.h in all the classes THEN what? - (my guess would be to itemize the objects again in their respective places in the header file a.k.a. public:, private: public slots: etc).
If there is a tutorial or example or another forum question, please don't hesitate to point me there :) - or any personal preferences on the implementation of Designer based gui's

14th August 2007, 14:28
I did almost the same thing...

1. In Qt Designer, name your form objectname something ie. myStackedPage1

2. In your build (I use VC++) add the .ui for the form file.
The build will generate an ui_myStackedPage1.h include file.

3. Create .cpp and .h files that are based on this UI file, similar
to how mainwindow does it for it's ui file.


class Page1Property : public QWidget, private Ui::myStackedPage1

Page1Property::Page1Property(QWidget *parent)
: QWidget(parent)

You now have access from within this class to setupUi() for this ui file.

In main you then scroll through the stacked widgets add a layout for each and
place you form on the appropriate page.

int pages = WorkspacestackedWidget->count();
QWidget *thisWidget;
QLabel *m_emptyPage;
for (int i = 1; i < pages; ++i)
// Install a layout manager for all of the stacked pages
StackedFormLayout = new QGridLayout;
thisWidget = WorkspacestackedWidget->widget(i);

myStackedPage1= new myStackedPage1


15th August 2007, 23:37
Thanks for the help. Should I say that I am pretty new to C++? Can you offer any more help - i.e. what would the myStackedPage1.h look like (abridged version) and what would myStackedPage1.cpp look like (also abridged version)? would appreciate it.