Solved QInputDialog with fixed size
Hello, this is in reference to the following documentation: http://doc.qt.io/qt-5/qinputdialog.html#details
The code works as expected, but I want the Dialogbox that pops up to have a fixed, non adjustable size. I tried the following:
QInputDialog *Dialog = new QInputDialog; Dialog->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); Dialog->setComboBoxEditable(false); QString NewTitle = Dialog->getText(MainWindow, tr("Set New Title"), tr("Enter new title:"), QLineEdit::Normal, CurrentTitle, &ok);
I also tried:
QVBoxLayout *layout = new QVBoxLayout; Dialog->setLayout(layout); Dialog->layout()->setSizeConstraint(QLayout::SetFixedSize); ...
While none of that produced an error, none of it worked. So am I missing something?
In the documentation about size policy, it is written that the fixed policy corresponds to :"The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).". Thus size is determined by sizeHint(). You can reimplement this function to be sure that it will give the result you want.
But, if you know the exact size that the dialog must have, a better solution is to use setFixedSize(width, height). By this way the dialog will always have the same size.
Hi and welcome to devnet,
QInputDialog::getTextis a static method so it won't make use of the size policy you set on the
Ahh thank you. Totally overlooked that while implementing.