Home > Mobile >  About the layout of the Qt5, feel very strange, there is no direction, everybody to help have a look
About the layout of the Qt5, feel very strange, there is no direction, everybody to help have a look

Time:09-25

I want to be in an inheritance from QMdiSubWindow interface implemented on a vertical layout, code is very simple, but the actual operation result is defeated, below is the test code,
 ContentWindowCL: : ContentWindowCL (QWidget * parent) : 
QMdiSubWindow (parent)
{
The setAttribute (Qt: : WA_DeleteOnClose);
SetWindowTitle (" aaaaa ");
SetObjectName (" content ");
The resize (200300);

//case 1: create three parts can be normal layout
//QWidget * titleBarM=new QWidget ();
//titleBarM - & gt; SetStyleSheet (background: "green");
//QWidget * toolBarM=new QWidget ();
//toolBarM - & gt; SetStyleSheet (background: "yellow");
//QWidget * toolBoxM=new QWidget ();
//toolBoxM - & gt; SetStyleSheet (background: "red");

//2: directly inherited from QWidget, with the UI files,
//CrTitleBarCL * titleBarM=new CrTitleBarCL ();
//titleBarM - & gt; SetStyleSheet (background: "green");
//CrToolBarCL * toolBarM=new CrToolBarCL ();
//toolBarM - & gt; SetStyleSheet (background: "yellow");
//CrToolBoxCL * toolBoxM=new CrToolBoxCL ();
//toolBoxM - & gt; SetStyleSheet (background: "red");

//3: inherits QWidget directly, without the UI file
Aaa * titleBarM=new aaa ();
TitleBarM - & gt; SetStyleSheet (background: "green");
BBB * toolBarM=new BBB ();
ToolBarM - & gt; SetStyleSheet (background: "yellow");
CCC * toolBoxM=new CCC ();
ToolBoxM - & gt; SetStyleSheet (background: "red");

QLayout * mainLayout=this - & gt; Layout ();
MainLayout - & gt; SetMargin (2);
MainLayout - & gt; SetSpacing (2);
MainLayout - & gt; AddWidget (titleBarM);
MainLayout - & gt; AddWidget (toolBarM);
MainLayout - & gt; AddWidget (toolBoxM);
}

The first case the results


In 2, 3 kinds of custom class I didn't add any code, the result of running


Why do I have such a difference??
The upper is such processing: mdiArea=new QMdiArea ();
QMainWindow - & gt; SetCentralWidget (mdiArea);

ContentWindow=new ContentWindowCL ();
MdiArea - & gt; AddSubWindow (contentWindow);
I want to define three Windows, let them in QMdiSubWindow vertical display, with all the way, I can think of trying all I can think of layout method, confident with an inherited from QFrame parts as QMdiArea child window, but still can't realize the vertical layout, where is the problem??????
Everyone help to analyze, thanks,




CodePudding user response:

Layout and style sheet is mutual influence,
You put the style sheet in custom class inside a try,

CodePudding user response:

reference 1st floor caiwei_cs response:
layout and style sheet no influence each other,
You put the style sheet in custom class inside a try,

No feeling of three QWidget derived class does not seem to be displayed,
If I add some button in the derived class UI controls, to be displayed, but without the effect of layout,


Seems in QT4 stylesheet to acting on the QWidget derived classes, needs to be rewritten paintEvent function,
So has a similar treatment for layout?? Don't know whether you need to reload QWidget function, such as sizeHint (),

CodePudding user response:

refer to the second floor u014724231 response:
Quote: refer to 1st floor caiwei_cs response:

Layout and style sheet is mutual influence,
You put the style sheet in custom class inside a try,

No feeling of three QWidget derived class does not seem to be displayed,
If I add some button in the derived class UI controls, to be displayed, but without the effect of layout,


Seems in QT4 stylesheet to acting on the QWidget derived classes, needs to be rewritten paintEvent function,
So has a similar treatment for layout?? Don't know whether you need to reload QWidget function, such as sizeHint (),

The layout and the derived it doesn't matter, you print it and see where control of position,

CodePudding user response:

I personally think QT layout is rubbish, it is better to write their own events to change position

CodePudding user response:

reference 4 floor CLHJSWE response:
I personally think QT layout is rubbish, it is better to write their own events to change position

Out this layout is very good ah, how?

CodePudding user response:

reference 5 floor wn0112 reply:
Quote: refer to 4th floor CLHJSWE response:

I personally think QT layout is rubbish, it is better to write their own events to change position

Out this layout is very good ah, how?


May my novice, a great god, could you tell me this layout to do

CodePudding user response:

refer to 6th floor CLHJSWE response:
Quote: refer to the fifth floor wn0112 reply:

Quote: refer to 4th floor CLHJSWE response:

I personally think QT layout is rubbish, it is better to write their own events to change position

Out this layout is very good ah, how?


May my novice, a great god, could you tell me this layout to do


CodePudding user response:

Inherited from QWidget subclasses of add

This - & gt; The setAttribute (Qt: : WA_StyledBackground, true);

Have a try

CodePudding user response:

refer to the eighth floor wn0112 response:
inherited from QWidget subclasses of add

This - & gt; The setAttribute (Qt: : WA_StyledBackground, true);

Try


This means is the use of CSS layout?
I wrote this
 
PushButton - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • Qt
  • Related