[SOLVED] Qt new QWidget opens new window

Issue

I’m creating a new subuclass of QWidget with: new TestView;
When I call that statement, a new window opens.

Further when I add this widget to a layout, the window “closes” and the widget is shown in the layout as it should in the first place.

How do I make sure that the widget isn’t displayed as a new window?

Can anybody help me?

Solution

How do I make sure that the widget isn’t displayed as a new window?

It happens because your widget is visible before you add it to the layout. Either you are calling show() or raise() early on your TestView object, or you do the same on a parent widget between its creation and the moment it is added to the layout.

If you are making visible your widgets in their constructors, that’s a really bad idea.

Answered By – UmNyobe

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *