Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble with resizing a QInputDialog

Trouble with resizing a QInputDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 734 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Dummie1138D 1 Reply Last reply
      3
      • SGaistS SGaist

        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.

        Dummie1138D Offline
        Dummie1138D Offline
        Dummie1138
        wrote on last edited by
        #3

        @SGaist I see, thanks. In any case, what would have been the issue with my resizing of the QInputDialog?

        Chris KawaC 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please show a picture of what you get.

          As for your custom button not showing, did you at any point call show on it ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Dummie1138D Dummie1138

            @SGaist I see, thanks. In any case, what would have been the issue with my resizing of the QInputDialog?

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            @Dummie1138 said):

            In any case, what would have been the issue with my resizing of the QInputDialog?

            QInputDialog uses the SetMinAndMaxSize on 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 to setFixedSize does 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.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved