Home > Mobile >  QT form change size after recovery, which controls cannot return to its original size
QT form change size after recovery, which controls cannot return to its original size

Time:11-22

Custom a title bar, there ((normal) to maximize, minimize, close) such as button,
Interface of a series of layout, including a QGroupBox, this QGroupBox is horizontal layout, there are two QLabel, a used to display the camera, a used to display information,
Interface event handling with event filter eventfilters,
Recently encountered such a problem, after running the program, to maximize the form after click the maximize button, click to make the form again to restore the original size, but is used to display the camera QLabel size has changed, not the normal size of interface, and is, in the event filter eventfilters implements double click camera QLabel can make him full screen, double click to restore the original size again, this function also has a problem, keep up with the following questions, are magnified after recovery is not the original size, I think two problems might be a reason, bosses help me have a look at what is going on,
 bool MainWindow: : eventfilters (QObject * o, QEvent * e) 
{
QMouseEvent * ev=static_cast & lt; QMouseEvent * & gt; (e);
If (e - & gt; The type ()==QEvent: : MouseMove)//mouse
{
if(! IsMax)
{
//as long as the mouse mouse will change the style, and detect whether the mouse on the borders
SetMouseStyle (getMouseArea (ev - & gt; Pos ()));
//determine whether click move title
If (mousePressed)
{
QWidget * pw=this - & gt; ChildAt (pressedPoint);
If (pw==UI - & gt; My_title | | pw==UI - & gt; Ico)
{
Move (this - & gt; Pos () + ev - & gt; GlobalPos () - pressedPoint2);
PressedPoint2=ev - & gt; GlobalPos ();
}
}
If (ischange)
{
ChangeWidgetSize (ev - & gt; GlobalPos ());
}
}
}
Else if ((o==UI - & gt; CentralWidget) & amp; & (e - & gt; The type ()==QEvent: : MouseButtonPress))//frame mouse press
{
If (curEvent!=NON)//if on the frame and press the left key
{
Ischange=true;
M_StartGeometry=this - & gt; Geometry ();
}
}
Else if (e - & gt; The type ()==QEvent: : MouseButtonRelease)//mouse lift
{
MousePressed=false;
Ischange=false;
CurEvent=NON;
}
Else if ((o==UI - & gt; My_title) & amp; & E - & gt; The type ()==QEvent: : MouseButtonDblClick)//double click on the title bar
{
if(! IsMax)
{
IsMax=true;
This - & gt; ShowMaximized ();
}

The else {
IsMax=false;
This - & gt; ShowNormal ();
}
}
Else if ((o==UI - & gt; My_title | | o==UI - & gt; Ico) & amp; & E - & gt; The type ()==QEvent: : MouseButtonPress)//title, press
{
If (ev - & gt; Button ()==Qt: : LeftButton)
{
MousePressed=true;
PressedPoint=ev - & gt; Pos ();//the mouse position relative to the form
PressedPoint2=ev - & gt; GlobalPos ();//the mouse position relative to the desktop
}
}
Else if ((o==UI - & gt; Wenduchartview) & amp; & (e - & gt; The type ()==QEvent: : MouseButtonDblClick))//double temperature humidity chart
{
If (UI - & gt; Wenduchartview - & gt; IsFullScreen ())
{
The UI - & gt; Wenduchartview - & gt; SetWindowFlags (Qt: : SubWindow);
The UI - & gt; Wenduchartview - & gt; ShowNormal ();
}
The else {
The UI - & gt; Wenduchartview - & gt; SetWindowFlags (Qt: : Dialog);
The UI - & gt; Wenduchartview - & gt; ShowFullScreen ();
}
}
Else if ((o==UI - & gt; Shiduchartview) & amp; & (e - & gt; Type ()==QEvent: : MouseButtonDblClick))//double-click the humidity, the humidity diagram
{
If (UI - & gt; Shiduchartview - & gt; IsFullScreen ())
{
The UI - & gt; Shiduchartview - & gt; SetWindowFlags (Qt: : SubWindow);
The UI - & gt; Shiduchartview - & gt; ShowNormal ();
}
The else {
The UI - & gt; Shiduchartview - & gt; SetWindowFlags (Qt: : Dialog);
The UI - & gt; Shiduchartview - & gt; ShowFullScreen ();
}
}
Else if ((o==UI - & gt; M_camera) & amp; & (e - & gt; The type ()==QEvent: : MouseButtonDblClick))//double cameras
{
If (UI - & gt; M_camera - & gt; IsFullScreen ())
{
The UI - & gt; M_camera - & gt; SetWindowFlags (Qt: : SubWindow);
The UI - & gt; M_camera - & gt; ShowNormal ();
The UI - & gt; M_camera - & gt; The resize (camera_size);
Int with=UI - & gt; M_camera - & gt; Width ();
Int height=UI - & gt; M_camera - & gt; Height ();
QDebug () & lt; & lt;" Of the reduced width="& lt; }
Else if ((o==UI - & gt; Shiduchartview) & amp; & (e - & gt; Type ()==QEvent: : Enter))//mouse into the popup tooltip
{
The UI - & gt; Shiduchartview - & gt; SetToolTip (" double-click the biggest/minimize ");
}
Else if ((o==UI - & gt; M_camera) & amp; & (e - & gt; Type ()==QEvent: : Enter))//mouse into the popup tooltip
{
The UI - & gt; M_camera - & gt; SetToolTip (" double-click the biggest/minimize ");
}
Return QWidget: : eventfilters (o, e);
}


//minimize 
Void MainWindow: : chickMin ()
{
This - & gt; ShowMinimized ();
}

//maximize
Void MainWindow: : chickMax ()
{
if(! IsMax)//not maximizing the maximization,
{
IsMax=true;
This - & gt; ShowMaximized ();
}
The else {
IsMax=false;
This - & gt; ShowNormal ();
}
}

//close
Void MainWindow: : chickClose ()
{
QDebug () & lt; & lt;" Click on close ";
This - & gt; Close ();
}

CodePudding user response:

You this is adaptive window zooming, suggest inside resizeEvent implementation, window size change triggers resizeEvent, window initial size compared with the size of the current window to get a scaling factor, all controls in the window size and location are multiplied by the coefficient

CodePudding user response:

Give you a look at the rendering, this is normal in the interface size
This is to click the maximize and returned to normal after the interface controls the size of the
Other part of the normal, this appearance looks like the Label size enlarged the layout of cameras, then the line chart below to enlarge the size, why use showNormal () function can't restore the size of the amplifier before

CodePudding user response:

Put your control in the layout, had better be gridlayoutnullnull
  •  Tags:  
  • Qt
  • Related