Results 1 to 6 of 6

Thread: QDateEdit Resize for Changed Display Format?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

    Question QDateEdit Resize for Changed Display Format?

    Hi All,

    I'd like to be able to change the date format in QDateEdit widgets dynamically. QDateEdit::setDisplayFormat() changes the displayed format but does not cause the geometry of the widget to change to accommodate longer text.

    The example code generates three QDateEdits. The first two have their display format set before display and they size well. The third has its display format changed after display and stays at the default size (like the first widget). All this is on QT 4.5.1 on Linux.

    I have three questions:
    • Is it reasonable to expect the third editor to resize?
    • Is there a way to force a geometry rethink on the layout or parent widget?
    • Am I looking at a bug in Qt?

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5.  
    6. QApplication app(argc, argv);
    7. QWidget widget;
    8.  
    9. // My locale, in case it has a bearing
    10. QLocale::setDefault(QLocale(QLocale::English, QLocale::Australia));
    11.  
    12. // default date format (d/mm/yy), right size for format
    13. QDateEdit *date1 = new QDateEdit(QDate::currentDate(), &widget);
    14.  
    15. // wider date format, set before widget show(), right format and size
    16. QDateEdit *date2 = new QDateEdit(QDate::currentDate(), &widget);
    17. date2->setDisplayFormat("dd-MMM-yyyy");
    18.  
    19. // Another wider date format but set after widget show()
    20. QDateEdit *date3 = new QDateEdit(QDate::currentDate(), &widget);
    21.  
    22. QFormLayout *form = new QFormLayout;
    23. form->addRow("Default", date1);
    24. form->addRow("Wider 1", date2);
    25. form->addRow("Wider 2", date3);
    26.  
    27. widget.setLayout(form);
    28. widget.show();
    29.  
    30. date3->setDisplayFormat("dd-MMM-yyyy"); // changes format but not widget size
    31. // How do I force the geometry to be rethought after the parent widget is shown?
    32. // The date3 widget sizeHint() is updated by the change
    33.  
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 5th June 2009 at 06:23.

Similar Threads

  1. Replies: 1
    Last Post: 15th April 2009, 09:00
  2. How can you display binary data in hex format?
    By Cruz in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 14:40
  3. how to display images in mosaic format?
    By Nithya in forum Qt Programming
    Replies: 14
    Last Post: 24th April 2008, 06:41
  4. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48

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.