Home > Mobile >  In Qt layout style doesn't work
In Qt layout style doesn't work

Time:10-03

Int main (int arg c, char * argv [])
{
QApplication a (arg c, argv);
QWidget * w=new QWidget ();


QPushButton * for=new QPushButton (" load ", w);
QPushButton * button2=new QPushButton (" remove ", w);
For the - & gt; SetSizePolicy (QSizePolicy: : Expanding, QSizePolicy: : Expanding);
Button2 - & gt; SetSizePolicy (QSizePolicy: : Expanding, QSizePolicy: : Expanding);
For the - & gt; SetMinimumSize (60, 30);
Button2 - & gt; SetMinimumSize (60, 30);

QLabel * label1=new QLabel (w);
Label1 - & gt; SetText (" line ");
QLabel * label2=new QLabel (w);
Label2 - & gt; SetText (" column ");
QLabel * label3=new QLabel (w);
Label3 - & gt; SetText (" size ");

QLineEdit * rowEdit=new QLineEdit (w);
QLineEdit * colEdit=new QLineEdit (w);
QLineEdit * sizeEdit=new QLineEdit (w);

QFormLayout * fLayout=new QFormLayout (w);
FLayout - & gt; SetSpacing (20);
FLayout - & gt; SetLabelAlignment (Qt: : AlignRight);
//add components to form layout manager
//fLayout - & gt; AddRow (" : ", rowEdit);
//fLayout - & gt; AddRow (" column: "colEdit);
//fLayout - & gt; AddRow (" size: "sizeEdit);
QVBoxLayout * vlayout=new QVBoxLayout (w);
QHBoxLayout * hlayout1=new QHBoxLayout (w);
QHBoxLayout * hlayout2=new QHBoxLayout (w);
QHBoxLayout * hlayout3=new QHBoxLayout (w);
QHBoxLayout * hlayout4=new QHBoxLayout (w);
Hlayout1 - & gt; SetSpacing (20);
Hlayout2 - & gt; SetSpacing (20);
Hlayout3 - & gt; SetSpacing (20);
Hlayout4 - & gt; SetSpacing (20);

Hlayout1 - & gt; AddWidget (label1);
Hlayout1 - & gt; AddWidget (rowEdit);
Hlayout2 - & gt; AddWidget (label2);
Hlayout2 - & gt; AddWidget (colEdit);
Hlayout3 - & gt; AddWidget (label3);
Hlayout3 - & gt; AddWidget (sizeEdit);

Hlayout4 - & gt; AddWidget (for);
Hlayout4 - & gt; AddWidget (button2);

Vlayout - & gt; SetSpacing (50);
Vlayout - & gt; AddLayout (hlayout1);
Vlayout - & gt; AddLayout (hlayout2);
Vlayout - & gt; AddLayout (hlayout3);
Vlayout - & gt; AddLayout (hlayout4);


W - & gt; SetLayout (vlayout);

W - & gt; Show ();
Return a.e xec ();
}


Then also heard that because there is no delete the style of the UI is automatically generated so that https://blog.csdn.net/xinzhiyounizhiyouni/article/details/44521501


But still, first aid

CodePudding user response:

The great god do me a favor, for several hours, haven't solve,,,

CodePudding user response:

SetContentWidget this function if it won't, which is to add a header file, seems to be useless, qt version - opensource - Windows - x86-5.11.0

CodePudding user response:

The
 QFormLayout * fLayout=new QFormLayout (w); 
FLayout - & gt; SetSpacing (20);
FLayout - & gt; SetLabelAlignment (Qt: : AlignRight);

Comment out the

CodePudding user response:

QFormLayout * fLayout=new QFormLayout (w);
Don't set the parent, changing
QFormLayout * fLayout=new QFormLayout ();
Can, measurement is feasible

CodePudding user response:

BTW, for the layout, two associated widgets ways, one is the new layout specifies the parent, the other is a through the widget - & gt; Setlayout way, both with one can

CodePudding user response:

Agree with upstairs
  •  Tags:  
  • Qt
  • Related