Results 1 to 10 of 10

Thread: Align QDialog

  1. #1
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Exclamation Align QDialog

    Hello
    I need to change the size of a QDialog during its execution and that the utilizao this.setGeometry (0,0,500,700). The problem is that QDialog appears in the top left corner that is in position (0,0). Is there any function that allows for a QDialog in the center of the screen?



    Daniel Sousa

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Align QDialog

    use
    Qt Code:
    1. dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Align QDialog

    Quote Originally Posted by Lykurg View Post
    use
    Qt Code:
    1. dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));
    To copy to clipboard, switch view to plain text mode 
    It works perfectly. Thank you.

  4. #4
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Align QDialog

    Quote Originally Posted by Lykurg View Post
    use
    Qt Code:
    1. dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));
    To copy to clipboard, switch view to plain text mode 
    Is there any way to set the size of QDialog that function?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Align QDialog

    substitute dialog->size() with any size (QSize) you want.

  6. #6
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Align QDialog

    Quote Originally Posted by Lykurg View Post
    substitute dialog->size() with any size (QSize) you want.
    I did the following:

    this->setGeometry(QStyle::alignedRect(Qt::LeftToRight , Qt::AlignCenter, 88, qApp->desktop()->availableGeometry()));

    But he gave me the following error:

    /Users/danielsousa/Qt/Interface-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/../Interface2/criareditaralerta.cpp:15: error: no matching function for call to 'QStyle::alignedRect(Qt::LayoutDirection, Qt::AlignmentFlag, int, const QRect)'

  7. #7
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Align QDialog

    yea well, 88 is an int, not a QSize. And there is no QSize implicit constructor with an single int as argument
    The error message is quite explicit btw

  8. #8
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Align QDialog

    Quote Originally Posted by totem View Post
    yea well, 88 is an int, not a QSize. And there is no QSize implicit constructor with an single int as argument
    The error message is quite explicit btw
    Yeah, but then how can I fix this?

  9. #9
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Align QDialog

    consider this a minute.
    In the previous version, you wrote
    Qt Code:
    1. dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));
    To copy to clipboard, switch view to plain text mode 
    then, you want to change QDialog's size. So, as lykurg said, you replace dialog->size() by the QSize you want.

    now, what is the QSize you choose ?
    88
    88 is not a QSize

    Q.E.D.

  10. The following user says thank you to totem for this useful post:

    sousadaniel7 (6th May 2012)

  11. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Align QDialog

    Read the documentation about QSize (just click the link!). See which constructors are provided.

  12. The following user says thank you to Lykurg for this useful post:

    sousadaniel7 (6th May 2012)

Similar Threads

  1. QTabWidget align
    By AlexD in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2012, 13:19
  2. QTextEdit align
    By mero in forum Qt Programming
    Replies: 5
    Last Post: 29th March 2011, 08:10
  3. Replies: 9
    Last Post: 25th March 2011, 21:22
  4. Question about align
    By Archa4 in forum Newbie
    Replies: 4
    Last Post: 14th March 2011, 08:36
  5. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.