Results 1 to 9 of 9

Thread: QMessageBox: Controlling the width

Hybrid View

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

    Default Re: QMessageBox: Controlling the width

    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QApplication app(argc, argv);
    8.  
    9. QMessageBox msgBox1;
    10. // msgBox1.setMinimumWidth(400); // seemingly ignored, always same width box
    11. // msgBox1.setFixedSize(QSize(400, 200)); // also no effect
    12. // msgBox1.setFixedSize(400, 200);
    13.  
    14. dw.setFixedSize(100, 100);
    15. msgBox1.layout()->addWidget(&dw);
    16.  
    17. msgBox1.setWindowTitle("Width 400");
    18. msgBox1.setText("<strong>Warning</strong>");
    19. msgBox1.setInformativeText(
    20. "You have not entered hours against this event<br /> "
    21. "Do you wish to save the event anyway?");
    22. msgBox1.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    23. msgBox1.setDefaultButton(QMessageBox::No);
    24. msgBox1.setIcon(QMessageBox::Warning);
    25. msgBox1.show();
    26.  
    27. QMessageBox msgBox2;
    28. // msgBox2.setMinimumWidth(800); // seemingly ignored, always same width box
    29. // msgBox2.setFixedSize(QSize(800, 200));
    30. // msgBox1.setFixedSize(800, 200);
    31. msgBox2.setWindowTitle("Width 800");
    32. msgBox2.setText("<strong>Warning</strong>");
    33. msgBox2.setInformativeText(
    34. "You have not entered hours against this event<br /> "
    35. "Do you wish to save the event anyway?");
    36. msgBox2.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    37. msgBox2.setDefaultButton(QMessageBox::No);
    38. msgBox2.setIcon(QMessageBox::Warning);
    39. msgBox2.exec();
    40.  
    41. return app.exec();
    42. }
    43.  
    44. // vi: sw=4 ts=4 et
    To copy to clipboard, switch view to plain text mode 

    and result is attached. Not sure it proves anything though.
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: QMessageBox: Controlling the width

    this proves that the messagebox is not calling setFixedSize() internally. So i think we cannot do anything..

    the only way to debug now it to study qmessagebox.cpp and qmessagebox.h in, may be add these files to your project and debug, so that you can safely make some modifications.

  3. #3
    Join Date
    Jul 2009
    Posts
    10
    Thanked 1 Time in 1 Post

    Default Re: QMessageBox: Controlling the width

    Turns out the layout box in the QMessageBox is a grid (or at least it is in 4.5.2). You can force the resize using a spacer this way:

    Qt Code:
    1. QMessageBox msgBox;
    2. QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    3. msgBox.setText( "SomText" );
    4. QGridLayout* layout = (QGridLayout*)msgBox.layout();
    5. layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
    6. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 

    That will force the width to a minumum of 500, but it is allowed to be larger.

  4. The following user says thank you to thePoet for this useful post:

    astodolski (12th June 2014)

Similar Threads

  1. QMessageBox misbehaves after QFileDialog call
    By MikeG in forum Qt Programming
    Replies: 8
    Last Post: 2nd June 2009, 11:17
  2. Replies: 4
    Last Post: 15th October 2008, 14:24
  3. Scaling of pen width in QGraphicsView
    By spuds in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2008, 02:47
  4. QTableWidget column width and resizing
    By shooogun in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2008, 23:31
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 23:34

Tags for this Thread

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.