ChrisW67
5th June 2009, 06:18
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?
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;
// My locale, in case it has a bearing
QLocale::setDefault(QLocale(QLocale::English, QLocale::Australia));
// default date format (d/mm/yy), right size for format
QDateEdit *date1 = new QDateEdit(QDate::currentDate(), &widget);
// wider date format, set before widget show(), right format and size
QDateEdit *date2 = new QDateEdit(QDate::currentDate(), &widget);
date2->setDisplayFormat("dd-MMM-yyyy");
// Another wider date format but set after widget show()
QDateEdit *date3 = new QDateEdit(QDate::currentDate(), &widget);
QFormLayout *form = new QFormLayout;
form->addRow("Default", date1);
form->addRow("Wider 1", date2);
form->addRow("Wider 2", date3);
widget.setLayout(form);
widget.show();
date3->setDisplayFormat("dd-MMM-yyyy"); // changes format but not widget size
// How do I force the geometry to be rethought after the parent widget is shown?
// The date3 widget sizeHint() is updated by the change
return app.exec();
}
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?
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;
// My locale, in case it has a bearing
QLocale::setDefault(QLocale(QLocale::English, QLocale::Australia));
// default date format (d/mm/yy), right size for format
QDateEdit *date1 = new QDateEdit(QDate::currentDate(), &widget);
// wider date format, set before widget show(), right format and size
QDateEdit *date2 = new QDateEdit(QDate::currentDate(), &widget);
date2->setDisplayFormat("dd-MMM-yyyy");
// Another wider date format but set after widget show()
QDateEdit *date3 = new QDateEdit(QDate::currentDate(), &widget);
QFormLayout *form = new QFormLayout;
form->addRow("Default", date1);
form->addRow("Wider 1", date2);
form->addRow("Wider 2", date3);
widget.setLayout(form);
widget.show();
date3->setDisplayFormat("dd-MMM-yyyy"); // changes format but not widget size
// How do I force the geometry to be rethought after the parent widget is shown?
// The date3 widget sizeHint() is updated by the change
return app.exec();
}