Home > other >  In the main window in the constructor of add QWidget controls such as why show not to come out
In the main window in the constructor of add QWidget controls such as why show not to come out

Time:09-29

Constructor as follows: the MainWindow: : MainWindow (QWidget * parent) : QMainWindow (parent), UI (new UI: : MainWindow) {UI - & gt; SetupUi (this); This - & gt; SetWindowFlags (Qt: : FramelessWindowHint); This - & gt; SetWindowFlags (Qt: : Windows); This - & gt; ShowFullScreen (); Taishiback=new QWidget. Taishiback - & gt; ,0,800,600 setGeometry (0);//taishiback - & gt; SetAutoFillBackground (true);//UI - & gt; VerticalLayout - & gt; AddWidget (taishi);//taishiback - & gt; Show ();//taishiback - & gt; SetParent (this); Lab1=new QLabel; Lab1 - & gt; SetGeometry (0110 0,50,100); Lab1 - & gt; SetText (" 1234555 "); Lab1 - & gt; SetParent (this); } to see many routine use layout managers, don't use cannot be displayed? And where there is a problem? If this does not add the new controls, so should use this member function?

CodePudding user response:

LZ you this writing is not an error? Right should write QWidget so * taishiback=new QWidget (this);

CodePudding user response:

QMainWindow setCentralWidget (), please set control center

CodePudding user response:

//taishiback - & gt; Show (); Why do you want to comment out? Encountered this problem before, and the show will be displayed, commented how display have a look at the UI files are generated that ui_XXXXX. H file, where the function is called the show

CodePudding user response:

Don't come out, and finally in the interface directly pulled a, but this method sets the background color, and still on the road is not easy

CodePudding user response:

Add the following code QWidget * taishiback=new QWidget; Taishiback - & gt; SetGeometry (420370320-30); QPalette the palette. The palette. SetBrush (QPalette: : Background, QBrush (Qt: : red)); Taishiback - & gt; SetPalette (palette); Taishiback - & gt; SetEnabled (true); Taishiback - & gt; SetAutoFillBackground (true); Taishiback - & gt; SetParent (this); Display a red rectangular patten form the lower right corner

CodePudding user response:

Don't add the layout editor are easy to be blocked by other controls, naturally can not see

CodePudding user response:

SetParent (centerWidget ());
  • Related