[Solved]Adding custom widget ( class ) into made in Qt Designer ui class
I have a custom widget class ( inherited from QWidget ) and an UI class made in Qt Designer and attached to mainwindow widget by ..->setupUi(…) method.
In the UI class I’ve put QWidget in Qt Designer ( empty region ) and I need to put inside it my custom widget class ( inherited from QWidget ).
I tried to make this by setting parent when construction custom widget class:
But I get segmentation fault on Linux when I run the program. When I comment the last row:
There is no seg. fault but image_preview is not added to intern UI class.
Does anybody know how to add the custom widget image_preview to the UI class member intern->widget_image , so the widget will be seen and active on the UI?
Thanks a lot for help.
My custom widget is:
I’ve made in addition to promoting to custom widget at Qt Designer :
- //constructing image viewing:
- image_preview=new ImageView(intern->widget_image);
But I still get segmentation fault when running the program.
What could be wrong?
you need a layout on the intern->widget_image
Ok I’ve added vertical layout but still I get segmentation fault yet. I try to fix.
If my custom widget inherited from QScrollArea
1) can I promote in Qt Designer QWidget to ImageView?
2) If I add QScrollArea from Widget Box in Qt Designer to the Ui I see in Object Inspector actually 2 widgets added QScrollArea and scrollAreaWidgetContents, what widget should I promote to my custom widget ImageView so as to get it visible and active at the Ui?
don’t call setParent, but call the constructor with the parent
I passed the ui’s widget as the parent parameter to the custom widget constructor.
Sorry, I never used promoting widgets in designer. I usually just put a QWidget as a dummy container and add a layout and my custom widget later in C++.
Ok. I added layout and the custom widget to it inside ui_internal.h ( uic generated ) as:
- ImageView *image_view_widget;
- image_view_widget = new ImageView();
But I can’t access the image_view_widget as another public members of
- class Ui_Internal
yet in the code by intern->image_view_widget . Volker , Can you show some code example ? If no , ok I continue to resolve this issue it will be resolved of course with some time. Perhaps anybody else will help with this case.
There is additional way to add custom widget to ui class – to make Qt Designer plugin ( custom widget plugin ) , but now actually I need to add custom widget without compiling and adding it as a Designer plugin. Perhaps it will be made later – then we will have new widget inside Qt Designer Widget Box – special image processing widget , if it will be serious need in that I will make.
I will put a small example. Just for the moment:
Do not modify the ui_internal.h file – it is regenerated as soon as you clean and rebuild your project or you modify the .ui file it is generated from.
Also, you should try to instantiate the widgets on small test cases to see wether they work at all and then move forward to the more complex setup.
Also, replace your custom widgets with known to work widgets like a QTextEdit.
For Qt designer, plugin method will generate the identical *.ui file as promotion method. So making a plugin will not help you to sovle the problem.
Promotion will be the best method for you. If you still come with problem, you need to debug your code.And I think that the bug may be hidden in the place which you did not give here.
What widget to put to Qt Designer form appropriated for promotion to ImageView inherited from QScrollArea?
I’ve made promotion and I’ve got segmentation fault in place when this->centralWidget()->setVisible(true); called ( centralWidget contains intern ui that contains promoted to ImageView widget ). ( it is result of the debugging ).
I will provide later more information.Thanks for help, but the problem is not yet solved