Results 1 to 7 of 7

Thread: Resize QMainWindow without layout on it

  1. #1
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Resize QMainWindow without layout on it

    Hey,

    I have troubles on replacing items on resizeEvent of the QMainWindow - I am not using any layout, i just recalculate the new positions on resize.
    If the window is resized slowly there are not any troubles but if i resize it very fast by moving the mouse in crazy ways i get weird results....
    I added a "before resize" and a "after resize" screenshot to illustrate the problem.

    The Code looks like follows:
    Qt Code:
    1. void ClientMainWindow::resizeEvent(QResizeEvent * event){
    2. int heightPositionCorrection = (event->size().height()-event->oldSize().height())/2;
    3. int widthPositionCorrection = (event->size().width()-event->oldSize().width())/2;
    4.  
    5. ui.controlAirCondition->setGeometry(
    6. ui.controlAirCondition->geometry().x()+widthPositionCorrection,
    7. ui.controlAirCondition->geometry().y()+heightPositionCorrection,
    8. ui.controlAirCondition->geometry().width(),ui.controlAirCondition->geometry().height());
    9. ui.controlAlarmSystem->setGeometry(
    10. ui.controlAlarmSystem->geometry().x()+widthPositionCorrection,
    11. ui.controlAlarmSystem->geometry().y()+heightPositionCorrection,
    12. ui.controlAlarmSystem->geometry().width(),ui.controlAlarmSystem->geometry().height());
    13. ui.controlBlinds->setGeometry(
    14. ui.controlBlinds->geometry().x()+widthPositionCorrection,
    15. ui.controlBlinds->geometry().y()+heightPositionCorrection,
    16. ui.controlBlinds->geometry().width(),ui.controlBlinds->geometry().height());
    17. ui.controlHeating->setGeometry(
    18. ui.controlHeating->geometry().x()+widthPositionCorrection,
    19. ui.controlHeating->geometry().y()+heightPositionCorrection,
    20. ui.controlHeating->geometry().width(),ui.controlHeating->geometry().height());
    21. ui.controlLights->setGeometry(
    22. ui.controlLights->geometry().x()+widthPositionCorrection,
    23. ui.controlLights->geometry().y()+heightPositionCorrection,
    24. ui.controlLights->geometry().width(),ui.controlLights->geometry().height());
    25. ui.controlMusic->setGeometry(
    26. ui.controlMusic->geometry().x()+widthPositionCorrection,
    27. ui.controlMusic->geometry().y()+heightPositionCorrection,
    28. ui.controlMusic->geometry().width(),ui.controlMusic->geometry().height());
    29. ui.controlVideo->setGeometry(
    30. ui.controlVideo->geometry().x()+widthPositionCorrection,
    31. ui.controlVideo->geometry().y()+heightPositionCorrection,
    32. ui.controlVideo->geometry().width(),ui.controlVideo->geometry().height());
    33. ui.configScreen->setGeometry(
    34. ui.configScreen->geometry().x()+widthPositionCorrection,
    35. ui.configScreen->geometry().y()+heightPositionCorrection,
    36. ui.configScreen->geometry().width(),ui.configScreen->geometry().height());
    37. ui.controlPlaceholder->setGeometry(
    38. ui.controlPlaceholder->geometry().x()+widthPositionCorrection,
    39. ui.controlPlaceholder->geometry().y()+heightPositionCorrection,
    40. ui.controlPlaceholder->geometry().width(),ui.controlPlaceholder->geometry().height());
    41. }
    To copy to clipboard, switch view to plain text mode 
    before resizing.jpgafter resizing.jpg

    What am i doing wrong here?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Resize QMainWindow without layout on it

    I cannot get this to fail on Linux, though I assume from the screenshot that you are on Windows.

    Exactly what manipulation causes the effect you see? Does Windows allow you to drag beyond screen edge during resize (taking the icons with it)? Does the window then get constrained to the screen without a resize event bringing the icons back into the smaller size perhaps? Does the behaviour change if you call the QMainWindow::resizeEvent() at the end or your resize event?

    A couple of observations:
    • Since you are only moving the icons, not resizing them, you can use QWidget::move() and save yourself some typing.
    • In a similar vein, you don't need to go via geometry() to get the QWidget::x() and QWidget::y()

  3. #3
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Resize QMainWindow without layout on it

    Yeah, it's correct I am under windows (XP 32Bit, SP3)
    The manipulation I am using is the normal resize my clicking on the bottom right of the window and then doing the resize operation..
    I changed the code a bit to fit your ideas, but it did not fix the problem =/
    Qt Code:
    1. void ClientMainWindow::resizeEvent(QResizeEvent * event){
    2. if(/*resizing == false && */(event->size().height() > 500 || event->size().width() > 800)){
    3. //resizing = true;
    4. int heightPositionCorrection = (event->size().height()-event->oldSize().height())/2;
    5. int widthPositionCorrection = (event->size().width()-event->oldSize().width())/2;
    6.  
    7. ui.controlAirCondition->move(
    8. ui.controlAirCondition->x()+widthPositionCorrection,
    9. ui.controlAirCondition->y()+heightPositionCorrection);
    10. ui.controlAlarmSystem->move(
    11. ui.controlAlarmSystem->x()+widthPositionCorrection,
    12. ui.controlAlarmSystem->y()+heightPositionCorrection);
    13. ui.controlBlinds->move(
    14. ui.controlBlinds->x()+widthPositionCorrection,
    15. ui.controlBlinds->y()+heightPositionCorrection);
    16. ui.controlHeating->move(
    17. ui.controlHeating->x()+widthPositionCorrection,
    18. ui.controlHeating->y()+heightPositionCorrection);
    19. ui.controlLights->move(
    20. ui.controlLights->x()+widthPositionCorrection,
    21. ui.controlLights->y()+heightPositionCorrection);
    22. ui.controlMusic->move(
    23. ui.controlMusic->x()+widthPositionCorrection,
    24. ui.controlMusic->y()+heightPositionCorrection);
    25. ui.controlVideo->move(
    26. ui.controlVideo->x()+widthPositionCorrection,
    27. ui.controlVideo->y()+heightPositionCorrection);
    28. ui.configScreen->move(
    29. ui.configScreen->x()+widthPositionCorrection,
    30. ui.configScreen->y()+heightPositionCorrection);
    31. ui.controlPlaceholder->move(
    32. ui.controlPlaceholder->x()+widthPositionCorrection,
    33. ui.controlPlaceholder->y()+heightPositionCorrection);
    34. QMainWindow::resizeEvent(event);
    35. //resizing = false;
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 
    I added 3 Screenshots again - the behaviour is the same as before =(

    The one to the left is before resizing, the second from the left side is after "slow" resizing and the third one is after fast resizing (I am moving the mouse as fast as I can while I am holding the left mousebutton ... I move it in kinda circles very fast again and again before I release the left mouse button and this is what I get)

    before resizing.jpgafter slow resizing.jpgafter fast resizing.jpg

    From my point of view it seems like the "resizeEvent" is called too often, so that one resizeEvent breaks up the running one.. (like one event is NOT fully processed while the next already happend..) -> is that possible!?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resize QMainWindow without layout on it

    Quote from the QWidget::move method documentation : When changing the position, the widget, if visible, receives a move event (moveEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown. Maybe this is a problem.

  5. #5
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Resize QMainWindow without layout on it

    Hmm, ok - and if that's the problem ... how should i handle that? Any ideas?

  6. #6
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Resize QMainWindow without layout on it

    So does not anybody have an idea how to solve this? I think I got your point @Lesiok - but how do I solve that issue!?

  7. #7
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resize QMainWindow without layout on it

    Why do you use a movement based on the old and new window sizes ?

    Can't you just calculate a new position based on the new size ? So always calculate an absolute position, not a relative position compared to the old position. That would be much less error-prone.

    Regards,
    Marc

Similar Threads

  1. how to resize Qmainwindow with Qwidget ?
    By zeynepb.bil in forum Qt Programming
    Replies: 10
    Last Post: 28th September 2017, 23:48
  2. resize a QMainWindow
    By graciano in forum Newbie
    Replies: 4
    Last Post: 19th August 2009, 16:45
  3. Resize QWidget in QMainWindow
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2007, 12:16
  4. QMainWindow resize problem
    By edb in forum Qt Programming
    Replies: 5
    Last Post: 12th January 2007, 10:31
  5. How to resize a QMainWindow in QWorkspace.
    By s_a_white in forum Newbie
    Replies: 2
    Last Post: 17th July 2006, 18:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.