Results 1 to 11 of 11

Thread: On resize using Maximize Button, Dialog not appears in center of screen?

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default On resize using Maximize Button, Dialog not appears in center of screen?

    Hi all,

    I am working on Qt4.6 on mac os, I am working on MultiDialog Application. All the windows are in the layout, When I click on the maximize button on the top of the mainwindow appaers to be maximized. When i move from MainWindow to the next Dialog I want if MainWiindow is maximised then nextDialog should also be maximized.For this I used

    Qt Code:
    1. if(this->isMaximized())
    2. {
    3. nextDialog->showMaximized();
    4. }
    To copy to clipboard, switch view to plain text mode 

    It works perfectly fine. But When I click on nextDialog maximize button to restore it to its orginalGeometry, then it resizes it to the original width and height but not the position, I appears on the bottom right, for this I am trying to get the center position in the resize event of the dialog but still no use.

    For this I used:

    Qt Code:
    1. void nextDialog::resizeEvent(QResizeEvent * event)
    2. {
    3. this->move(QApplication::desktop()->screen()->rect().center()- this->rect().center());
    4. }
    To copy to clipboard, switch view to plain text mode 

    But It wont appear in the center

    I also tried this but again fails:

    Qt Code:
    1. void nextDialog::resizeEvent(QResizeEvent * event)
    2. {
    3. QDesktopWidget *d = QApplication::desktop();
    4. int dW = d->width();
    5. int dH = d->height();
    6. int mw = this->width();
    7. int mH = this->height();
    8. int cw = dW/2-mw/2;
    9. int ch = dH/2-mH/2;
    10. move(cw,ch);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Pls Suggest what should i do.
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    try using saveGeometry() and restoreGeometry().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    No, its also not working.
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    show your code with what you tried.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    I saved the original geometry that appears when the MainWindow appears.

    Qt Code:
    1. Void MainWindow::init()
    2. {
    3. QSettings settings("MyCompany", "MyApp");
    4. settings.setValue("geometry", saveGeometry());
    5. }
    To copy to clipboard, switch view to plain text mode 

    And on Next Dialog, On Resize Event, I restored that saved geometry.
    Qt Code:
    1. void NextDialog::resizeEvent(QResizeEvent * event)
    2. {
    3. QSettings settings("MyCompany", "MyApp");
    4. this->restoreGeometry(settings.value("geometry").toByteArray());
    5. }
    To copy to clipboard, switch view to plain text mode 

    Actually My Dialog is in the layout So, when I restore its orginal geometry then it restores the widget and On Maximize Button it expands without expanding the widgets inside the dialog.
    Always Believe in Urself
    Merry

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    Your code makes no sense.
    You are storing the geometry of your main window, and give that geometry to the dialog??
    You should restored the geometry for your main window!

    Actually My Dialog is in the layout
    How can that be? Dialog is a top level widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    Attached is the sample code for reference

    Unzip the code and run , There is one case in which i am getting problem:
    The case is:

    On Application Run, First click on the maximize Button on the top, after that On the "OK Button" -> On Click on OkButton -> it will show the next dialog, then click on the maximize Button on the top of this next dialog, It will not come in the centre of the screen.
    I had also, try to use saveGeometry() and restoreGeometry(). It is commented in the code, Uncomment it and try to run again, and see the result,

    Pls help me, what i am doing wrong?
    Attached Files Attached Files
    Always Believe in Urself
    Merry

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    I can't run your code where I am at.
    Maybe some one else can.
    I'll try looking at it in the evening if I have time.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    Nobody is there to solve my problem.

    Its very urgent, Pls help.
    Always Believe in Urself
    Merry

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    Qt Code:
    1. QDlg::QDlg(QWidget *parent):QDialog(NULL)
    2. {
    3. setupUi(this);
    4. OnInit();
    5. }
    To copy to clipboard, switch view to plain text mode 

    you are saving the geometry in OnInit() but you call OnInit() during construction time, during that time the geometry is not defined.
    You have to save the geometry after the dialog is visible, best as a reaction to resizing or moving.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. The following user says thank you to high_flyer for this useful post:

    merry (26th August 2011)

  12. #11
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: On resize using Maximize Button, Dialog not appears in center of screen?

    Thanks a ton high_flyer, its working.
    Always Believe in Urself
    Merry

Similar Threads

  1. Replies: 1
    Last Post: 23rd February 2010, 08:29
  2. Center dialog on screen problems
    By lalesculiviu in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2009, 13:15
  3. 'resize/maximize' button not visible
    By sindhumol_s in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2009, 02:15
  4. how to put a dialog in the center of the screen
    By biswajithit in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 12:24
  5. Show dialog in screen center
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2008, 13:41

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.