PDA

View Full Version : QWidget container / Promote a widget without using Creator or Designer



Gavin Harper
27th October 2010, 09:16
I have recently switched to designing my GUIs and all code in a text editor since I prefer writing in VIM and I often prefer working without X.

I'll try and keep this short and bulletpoint like.

I have hit one snag though that I cannot find any documentation on (Please correct me if I am wrong).

I have a QWT plot (this is not QWT specific, so I am posting here) that I want to include in my QVBoxLayout as part of the MainWindow.

The issue is that when I add the VBoxLayout to a QWidget window and then do window->show() the VBox appears as a new window.

I have set the background of the application to the Dark palette and the original window has the affected background colour but the Plot and anything in the VBox appears as a new window.

How do I get the QVBoxLayout to appear as part of the main window?


Thank you!

-Gavin

wysota
27th October 2010, 10:15
You are missing a layout on some level, most probably your VBoxLayout's parent widget is not placed in a layout.

I have no idea why does the title of this thread refer to promoting widgets, though.

Gavin Harper
27th October 2010, 10:21
The reason I used the terminology of promoting widgets is that that is what I did to obtain the same result in Creator.

Create a widget on the form -> promote widget -> include header + class name and it then appeared on the main window.

Thank you for your suggestion regarding adding parent widget. I will try that now!

wysota
27th October 2010, 10:35
The reason I used the terminology of promoting widgets is that that is what I did to obtain the same result in Creator.
From what I understand you just want to use a custom widget. But it has nothing to do with your problem. You'd be having the same problem if you wanted to use QPushButton or any of the other widget classes. Your C++ code is simply incorrect.

Gavin Harper
27th October 2010, 16:43
Solved.

I was adding my layout to a QWidget and doing widget->show(); instead of setCentralWidget(widget);