Adding custom widgets to QStackedWidget - qt

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).

If you're using QtCreator I suggest do it this way:
Design each page/widget as a seperate class (seperate *.cpp, *.h and *.ui files) - press ctrl+n and choose Qt / Qt designer form class.
Add X pages/widgets to the stackedWidget. X is the number of views You created
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.

Related

How can I create a system similar to QDockWidget but for tabs?

I had an idea I have no clue on how to implement. I'm working with Qt and I'ld like to have a system of tabs that allows me to use tabs in the same way one can use QDockWidgets, that is: with QDockWidgets one can pick a widget and use it floating around the monitor or he can dock it in a QMainWindow in any of the four sides. Well I would like to have such attribute with a QTabWidget! So suppose I have two QTabWidgets in front of me. With the proposed idea, I would be capable to drag and drop a tab (with its widget) from one QTabWidget to another or even simply undock it from its original QTabWidget and start using it independently as another QTabWidget with one tab.
Well I couldn't find a way to use QTabWidget this way "naturally"; it seems Qt doesn't provide such possibility with its pack of widget classes. So does anybody knows any project open to the public containing a class able to do such thing? Or how could I implement such a new class myself? (I don't know for example how could I make the drag and drop effect from a QTabBar since even if setMovable is set to true, still isn't possible to make the tab go away from area of the QTabBar.
Any help will be appreciated.
QDockWidgets already provide possibility to be tabbed.
You can check Dock Widgets Qt sample project in Main Windows section.
Screen of the just launched sample app:
Screen of the tabbed doc widgets:
Check this answer for implementation details.

How can I make two rows of tabs in Qt

I would like to have something like the following image. I want two rows of tabs. One is included in the other. Is using two QTabWidget the way to go? Also, I would like to mention that the program's main window will display this structure. If you have any suggestions...
I would like the tabs to look like the following (of course, not exactly; this handmade image is awful).
Image http://imageshack.us/a/img831/3889/subtabs.png
Use nested QTabWidgets: an outer primary tab which contains its own secondary QTabWidget (where one is necessary).
Since you are after specific look, then there are three possible solutions (ordered by complexity) :
See what you can do with Qt style sheets using nested QTabWidgets. See this answer for some example code, and of course reference in docs.
Forget QTabWidget, write your own, containing custom tab bar, and using a QStackedWidget or just nested QStackedLayout for tab contents. You can nest these custom tabbed widgets like you would with QTabWidget, or just have dynamic two-row
tab bar in one non-nested custom tab widget, it's your code now.
Start using QML for UI, perhaps just for a custom tab bar, perhaps for the whole central widget, depending on what you have there.
You can use QTabBar instead. A QTabWidget is formed from a QStackedWidget and a QTabBar, but you can use QTabBars directly - and have two or three or more layers of tabs.

make a new widget and use in a form

I'm new to the Qt Framework and Qt Creator, and I need to make a new widget with a UI contains some pushButtons, Labels, functions, and events and then use it in another form.ui.
or come to Qt desiner toolbox as custom widget.
in C# i use UserControl.
How can I do that?
i found promote to option but this is not my answer!
There is already documentation on how to create a Qt Designer custom widget. To be honest though, and this is a personal opinion, it is not really worth the effort unless this custom widget is extremely important to visualize in your UI layout.
You can just as easily create a placeholder widget or an empty layout for it in one UI design, and then add it to the layout in code later. The process is just simply:
Create custom widget as one UI
Create main UI with a an empty layout in the spot meant for custom widget
In code, addWidget to layout
Again, if you really need to visualize this custom widget in Designer, check out the docs. My perspective comes from a PyQt background where we use the Designer very very minimally just for complex layout design and do most of everything back in code anyways.

Classes to use for a flexible image selection/tagging widget in Qt

I'm new with Qt and am looking for advice on how to structure this.
I want a flexible widget that can display a set of images (normally read from a directory but other sources too) and let the user select images with the arrow keys and/or mouse and also apply custom tags.
For example there might be 5 tags defined by the application. A user can press a key to select one, and then a little icon would appear in or near the image preview showing that it was selected for that tag.
Would I need to implement this from scratch via drawing on a QWidget or is there something that would make a sensible base class? Thanks!
I would use a QListView base class, and then subclass QStyledItemDelegate.
There is an example here which might help you.

QT/PyQT best practice for using QT Designer

What is your development approach with QT/PYQT and QT Designer ?
Are you doing this:
Put all components on the panel (without any layout) and arrange them
Put components in layout (Align Vertically/Horizontally/Form/Grid)
Generate UI file and start coding
how do you manage when you have custom widget ? For example when you have to fine tune behaviour of a QButton or QLineEdit ? Is it possible to add this custom widget to designer?
Answer to part of your question:
Yes, it's possible to add custom widgets to the designer. You have two alternatives:
You can write a full-fledged designer plugin - see Creating Custom Widgets for Qt Designer for a full example.
You can promote widgets - i.e., you pick an already existing widget that's similar in looks and/or functionality to the widget you'll be creating at runtime, you place the "mock" widget on the form, you right click it, and you "promote" it to the actual type of the final widget you'll be using. At runtime, the form parser will create your actual widget instead of the placeholder. See Using Custom Widgets with Qt Designer > Promoting Widgets for more details.

Resources