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. QInputDialog with fixed size
Forum Updated to NodeBB v4.3 + New Features

QInputDialog with fixed size

Scheduled Pinned Locked Moved Solved General and Desktop
qdialogqinputdialogsize
4 Posts 3 Posters 7.3k Views 1 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.
  • Y Offline
    Y Offline
    YokeM
    wrote on 14 Mar 2018, 13:52 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alain38 0
      wrote on 14 Mar 2018, 14:52 last edited by
      #2

      Hi,
      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.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Mar 2018, 21:48 last edited by
        #3

        Hi and welcome to devnet,

        QInputDialog::getText is a static method so it won't make use of the size policy you set on the Dialog instance.

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

        Y 1 Reply Last reply 15 Mar 2018, 09:13
        4
        • S SGaist
          14 Mar 2018, 21:48

          Hi and welcome to devnet,

          QInputDialog::getText is a static method so it won't make use of the size policy you set on the Dialog instance.

          Y Offline
          Y Offline
          YokeM
          wrote on 15 Mar 2018, 09:13 last edited by YokeM
          #4

          @SGaist

          Ahh thank you. Totally overlooked that while implementing.

          1 Reply Last reply
          0

          2/4

          14 Mar 2018, 14:52

          • Login

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