Dynamic forms



  • What is the best way to change the items in a QFormLayout dynamically? I was hoping for a simple visible property but that does not seem to exist. I then tried creating two QFormLayout objects and put my common controls in one and the ones I want to conditionally hide in the other however this has some strange behavior. The first is that my columns will not line up (for obvious reasons) but the other one is that when I remove the non-common layout I still see the first row and then my common params are overlayed on top of that, I assume I am doing something wrong.

    This is how I am adding the form layouts (note this is in the initializePage of a Wizard I am working on):

    @
    layout()->removeItem(_master);
    layout()->removeItem(_common);
    if( someCondition )
    {
    layout()->addItem(_master);
    }
    layout()->addItem(_common);
    @

    Ideally though, even if this works I would prefer to use a single QFormLayout so my column widths remain consistent.

    Thanks.



  • Could you perhaps post a drawing or something like that of what you want to achieve?



  • For examples sake lets say I wanted to present a form to a user that captures there name and gender, then when a user clicked they were male or female I would then add some fields specific for that gender (in this case maybe its a health ins. form or something).

    In my case I am doing this with a wizard and know from the previous page what fields I want to display, a couple of them are common regardless of the previous page but then the others are not. I could probably recreate the form everytime in the initializePage function, I however have been trying to create all the controls in the constructor then modifying the layout in initializePage.


  • Moderators

    Have a look in the offical Qt book." You can download it here":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip
    In one of the first chapters they explain how to do something like what you want with example code..


Log in to reply
 

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