Trouble with resizing a QInputDialog
-
Hi. I have the following code.
QInputDialog passwordBox(this, Qt::Dialog); //Create custom dialogbox with greater control. bool ok; //Remove the cancel button, the question mark, and change the text to something we can use passwordBox.setOption(QInputDialog::NoButtons); //Remove all buttons //passwordBox.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); //passwordBox.size(); passwordBox.setFixedSize(600, 240); //Creat button and add button back to the layout QDialogButtonBox *okButton = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &passwordBox);While the horizontal size is adjusted, the vertical size is not adjusted. I am unsure why. I have made no settings related to the vertical size previously.
This may or may not be related but the okButton also does not show if the following line is added:
okButton->move(200, 100);Please let me know if more info is required.
-
Hi,
From the looks of it, it would be simpler to build your own dialog using QDialog, QLineEdit and QDialogButtonBox with a QVBoxLayout to hold all that.
-
Hi,
From the looks of it, it would be simpler to build your own dialog using QDialog, QLineEdit and QDialogButtonBox with a QVBoxLayout to hold all that.
@SGaist I see, thanks. In any case, what would have been the issue with my resizing of the QInputDialog?
-
Please show a picture of what you get.
As for your custom button not showing, did you at any point call show on it ?
-
@SGaist I see, thanks. In any case, what would have been the issue with my resizing of the QInputDialog?
@Dummie1138 said):
In any case, what would have been the issue with my resizing of the QInputDialog?
QInputDialog uses the
SetMinAndMaxSizeon its layout. See the source. This constraint means that the widget's min and max size is set to the min and max sizes of its contents. Since the label and line edit have fixed heights your dialog also gets a fixed height of their sum (plus margins and spacing). With this layout resize mode your call tosetFixedSizedoes not actually change the min and max values.You could change the mode like this
passwordBox.layout()->setSizeConstraint(QLayout::SetDefaultConstraint);and that would let you set the fixed size, but it's kinda ugly, because it relies on the widget's internals and, like SGaist said, you'd be better off creating your own dialog, since you want to customize it even more.
Btw. why do you want to remove the cancel button? It's an input dialog, so if users don't want to "talk" to you they should be able to back out of it. Seems like bad UX to remove that button.