Qt Designer, using a widget file in other window
I just installed Qt and made my first attempt at a gui design using Qt Designer.
My main window has 4 tabs. Each tab should have exactly the same content.
So I created a widget to hold the common content. Its a QLabel, a QLineEdit and a QTable Widget.
Is it possible to make the widget appear in each tab of the main window in the designer, or do I need to do this in code?
I am using Qt 5.4 on windows 7 64 bit. The msvc2013_64 designer.
Hi, welcome to devnet.
There are two ways to work with this:
- Add the common part to each tab from code
- Put an empty "placeholder" widget in each tab in the designer and use the "promotion mechanism":http://qt-project.org/doc/qt-5/designer-using-custom-widgets.html . This way you don't need to pollute code with boilerplate.
Neither of these will show the custom widget in the tabs in the designer though.
To do that you would have to create a "designer plugin":http://qt-project.org/doc/qt-5/qtdesigner-customwidgetplugin-example.html with your custom widget, which is probably an overkill for simple cases.
Thanks Cris. Just as I expected :-). I will redesing and make a fake tab with pushbuttons instead.
I would be a simple thing to add a code generator which creates a designer plugin from a widget.
The thing I don't like about the designer plugins is that they need to be compiled with Qt version and compiler used to build the QtCreator/Designer.
This is often something different than what you use for your own project so this becomes another maintenance burden, especially if you use MinGW for your project, as the stock QtCreator is built using (old) MSVC 2010. Then you need additional compiler and Qt kit with all the crust just to build a plugin.
I find it a lot less hustle to just go with the promotion, but that might not fit everyone's case of course.
This is why I dislike c++.
On windows, could the qt framework and designer be ported to managed c++? That would be nice since the bindings to all CLR languages will be for free.
It's actually not a c++ problem as it defines nothing about the ABI. It's the vendors that don't get along and don't maintain backwards compatibility. But that's a curse and a blessing at the same time.
Managed c++? You mean the abomination of C++/CLR? I'm almost certain it would be impossible, if not for the sole share of 3rd party libraries required for starters. OpenGL, ICU, DirectX, Webkit, all the platform specific APIs, python and perl needed for building... nah, forget it.
C++/CLR is dying anyway. Very few people are interested in it these days. Certainly not Microsoft anymore.