Results 1 to 3 of 3

Thread: QMessageBox Size

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QMessageBox Size

    I am trying to set the size of a message box that i have created as follows:

    Qt Code:
    1. QMessageBox msgBox(this);
    2. msgBox.setWindowTitle(tr("MailBox Location"));
    3.  
    4. msgBox.setInformativeText(tr("You must ..... and so on and so forth"));
    To copy to clipboard, switch view to plain text mode 


    I have tried the following:

    Qt Code:
    1. 1). msgbox.setGeometry ( int x, int y, int w, int h )
    2.  
    3. 2). msgbox.resize(int w, int h)
    To copy to clipboard, switch view to plain text mode 

    and nothing seems to affect the way the box is diplayed, interms of its size that is.

    any suggestion is welcomed.


    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMessageBox Size

    Looks like QMessageBox::showEvent() forces it to fixed size according to various factors. One ugly way to work it around is:
    Qt Code:
    1. class MyMessageBox : public QMessageBox {
    2. protected:
    3. void showEvent(QShowEvent* event) {
    4. QMessageBox::showEvent(event);
    5. setFixedSize(640, 480);
    6. }
    7. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Jul 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMessageBox Size

    It seems that reimplementing the function showEvent() is not the good way because a resizeEvent may occur after it. One (still ugly) way is to reimplement the resizeEvent function:
    Qt Code:
    1. class MyMessageBox : public QMessageBox {
    2. protected:
    3. void resizeEvent(QResizeEvent* event) {
    4. setFixedSize(640, 480);
    5. }
    6. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by J_Courbon; 20th July 2011 at 13:37. Reason: reformatted to look better

Similar Threads

  1. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  2. Resizing a QDialog to the content size
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2007, 08:16
  3. Replies: 1
    Last Post: 24th October 2006, 16:40
  4. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.