Resize a dialog box

  • Hi folks,

    How do I create a dialog box with hidden features to appear after a click of a button, like when a user wants to see the advanced options, then clicks an "advance" button and the dialog expands.
    I already know how to make the widgets come and go, but I can't make the window automatically resizes.

    I appreciate any help.

  • you connect the clicked of advance to a slot, in which you just do dialog->resize(w,h) and that should work!

    else, post your code here

  • Moderators

    You might check out "this post": which I think covers what you're talking about.

  • mlong that seems to be an older post dealing with Qt3 ... I just tried this:

    1. used designer to add a dialog and added a pushbutton to this dialog
    2. added signal slot to resize on button click

    and it just works

  • Moderators

    @chetankjain: I believe it is a Qt4-related thing. The example is basically showing how to use QLayout::setSizeConstraint to replace the old Qt3 QDialog::setResizeMode() functionality.

    I think resize() is ok if you know a fixed size you want to expand to, but this method allows the QLayout to determine the new size of the dialog. Often, especially when working with i18n and translations, or with differing system themes, you can't be sure of the size your dialog will need to be without having to do some dirty work with size hints and whatnot.

    Whichever way works best is left as an exercise to the programmer. I'm just sharing an alternative that has worked for me.

  • Thanks a lot,

    The chetankjain's idead works fine, I had to use the trial and error aproach, but it was fun.

    mlong did present a more automatic way of doing this, but somehow it doesn't work! The application suposedly executes but nothing appears on the screen, and after 18 to 20 seconds I get this:

    Starting C:\Qt\2010.05\SortDialog-build-desktop\debug\SortDialog.exe...
    C:\Qt\2010.05\SortDialog-build-desktop\debug\SortDialog.exe exited with code -1073741819

    Runnig in debugging mode returns an error coming from the


    It says:

    "The inferior stopped because it received a signal from the Operating System.

    Signal name: SIGSEGV
    Signal meaning: Segnentation fault"

    I have no idea of what this means.

  • Looks like a Windows 7 kind of problem. I'll just stick with the solution that works for me. If someone finds out what's going on with my setSizeConstraint I'll come back to this.

    Thanks everyone for the support.

  • delay, if you could post your code one of us will look at it @ setSizeConstraint issue

  • [quote author="Delay" date="1299977299"]Hi folks,

    How do I create a dialog box with hidden features to appear after a click of a button, like when a user wants to see the advanced options, then clicks an "advance" button and the dialog expands.
    I already know how to make the widgets come and go, but I can't make the window automatically resizes.

    I appreciate any help.[/quote]

    you can have a look at the example of the docs: "dialog extension":

    It works without fixed sizes

  • Thank you Gerolf, it really helped. I used the idea of working with connections, but instead of dealing with multiple layouts I used only a single layout and resized it as required.
    Setting a fixed size for the form's layout in Qt Designer makes the resizing not avaiable to the user and lets the resizing through code a litle bit easier, since I can just put high values and the widget sizer puts it in the ideal size.

    That's the solution I'll stick to.

    Thank you everybody.

  • Moderators

    No problem! I think a lot of good ideas were shared. I'd forgotten about Gerolf's example, as well. Good luck with your app!

  • All your links are broken. So, did i need to open a new question on the same subject, or follow here and comments links became no more relevant will be removed ?
    I also want to be able to extend dialog box window, but directly for the window can contain all the widget/containers. (for example, i dynamically add widgets who contains views on some other containers (groupBox), and then dimensions change when dynamic insertion happens... so lot of them become out of dialog box view (and then cut).
    I'm searching for a solution for the dialog box will automatically change his dimension for see all the full containers included.
    Thank you.

  • @mlong links are now broken... all of them.

  • Moderators

    @jerome_isAviable You should not expect all links to be valid after 5 years.
    And invalid links should not be removed because you would modify old posts so it will become more difficult to follow the thread history. Instead you can add new links.
    For this link
    I just googled for "qt dialog extensions" and found this:

  • @jsulm "You should not expect all links to be valid after 5 years."
    why do you think that "i should expect all links to be valid after 5 years" ?
    tell that "i should expect" is a choice from your mind invention, because nothing relevent would show that "i should expect".
    I just signal that links are all broken... what's wrong with that ? are you serious man ? keep calm please.

    But also, the link you share here is something i read allready and not answer to the target question to... so i definitly not understand why you answer like that.

    You affirm to know what "should" be or not... not only for yourself, but for all other... Do i should tell you thank you for that to ?
    Also, if you "just googled" it is your choice to "just googled", maybe some other don't want to use google (who are you for tell people what they should do and thinking ? God himself ?).
    In the same way, i can answer: "why not just paste links you find, why choose to write an answer so agressive ?"
    Please do respect people who has not necessary the obligation to think same than you and just said signal things, just do it for show you can be able to respect people, and then, be respectable.
    Thank you for change tonality of your answer in the way of respect (or ignore me please).

  • administrators

    @jerome_isAviable tone of voice is a hard thing online. Most of us here are not native english speakers, writing in our second or third language.

    The general trend is to write in short sentences that contain only the essential. This comes over in many cultures as slightly offensive, something that it is not meant to be. Making interpretations on wording when there are two translations in between (the original poster from their native language in which they think and you to your native language) is mostly useless.

    As for your original question, open a new thread, as this one is five years old. Most people on this thread will probably not follow it anymore.

  • @tekojo thank you for take time for this answer, that is fine.
    Sure, from communication proffessionals on communication, in all langages, answer that: "you should this, you should that..." or "I just do that and..." (why "just" ? what is the signification back to this kind of formulation ? my english friends filling like me... tell me that it is a pretentious answer), and except to use specific tools that people not have to use too, is like to tell them: "you are stupid" and "you have to do same me, because i think i am the best and i want it like that".

    No one want to be traited like that, definitely.

    I really more appreciate your mediation way of answer, who is pretty nice.

    thank you again for your mediation intervention.

  • administrators

    @jerome_isAviable you are welcome.

    Hope you get an answer to your resize problem.

  • Not sure about what you try to do, so.. let me know if my answer help you or not:

    for alert error message, you can use QMessageBox this way:

    on conditional error test happen, just open QMessageBox the easy way:

    bool error(true);
    QString my_data("just for have a look");
      QMessageBox::warning(this, tr("my title on top bar window dialog here"), tr("my error message with data: %1).arg(my_data));

    and that's all. look at Qt API for QMEssageBox, there is different alert method to... and also, from there you have allready 2 buttons inside the dialog box, you can also change the text of button, and interact with the answer easy. This is well describe in the API of QMessageBox.
    if you want to catch events from button (i don't know for do what... but why not ?) you need to connect signal from QMessageBox you create to a SLOT (see on QObject member function: "connect" for that).
    you can also add buttons to easy and catch event with "switch()" C++ function because QMessageBox give back a int type of answer related to the button clicked.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.