Mafster
Mafster

Reputation: 107

Adding custom widgets to QStackedWidget

I'm having difficulty adding a custom widget to a QStackedWidget. I want to include a widget with a different grid layout in this stacked widget.

If someone could show me how to set up the layout (buttons, etc.) inside the stacked widget, that would be even better. The main dialog containing the stacked widget is really simple, and I don't want to clutter it up with tonnes of grid just for one widget inside the stacked widget.

At the moment I'm trying to make the complex widget as a seperate class and insert an instance of this class into the stacked widget using .addWidget() (this doesn't work).

Maybe I'm thinking about it the wrong way?

I'm using PyQt, but C++ answers are acceptable — I can get an idea of how things work by looking at C++ (well, I've been fine so far =s).

Upvotes: 1

Views: 5166

Answers (1)

Sebastian Dusza
Sebastian Dusza

Reputation: 2528

If you're using QtCreator I suggest do it this way:

  1. Design each page/widget as a seperate class (seperate *.cpp, *.h and *.ui files) - press ctrl+n and choose Qt / Qt designer form class.
  2. Add X pages/widgets to the stackedWidget. X is the number of views You created
  3. Promote each widget to be your custom designed page (right click in the objects tree on the right and choose promote widget). In field "promoted class name enter" enter the name of your cutom creacted page.

This should get you starded. I hope it solves Your problem. Ofcourse You have to design each view.

Upvotes: 2

Related Questions