[SOLVED] What should i do to resize the dialog the proper way?



  • So i have this dialog,

    !http://i.imgur.com/O4hye.png(Image 1)!

    the arrow thing is a checkbox and when you click it:

    !http://i.imgur.com/tpfgG.png(Image 2)!

    when you click it back (uncheck)

    !http://i.imgur.com/uvebp.png(Image 3)!

    And this is ugly not resizing the dialog back like image 1. Am i right? So i have no idea how to do it because ->resize won't work in this case.
    My code creating the dialog

    @ createOptionsGroupBox();
    createButtonsLayout();
    mainLayout = new QVBoxLayout;
    mainLayout->addWidget(optionsGroupBox);
    mainLayout->addLayout(buttonsLayout);
    setLayout(mainLayout);

    void custom_command::createOptionsGroupBox()
    {
    optionsGroupBox = new QGroupBox();
    optionsGroupBoxLayout = new QGridLayout;
    optionsGroupBoxLayout->addWidget(ui->label, 0, 0, 2, 2);
    optionsGroupBoxLayout->addWidget(ui->label_2, 2, 0);
    optionsGroupBoxLayout->addWidget(ui->de, 2, 1);
    optionsGroupBoxLayout->addWidget(ui->checkBox, 3,0);
    optionsGroupBoxLayout->addWidget(ui->label_4, 4, 0);
    optionsGroupBoxLayout->addWidget(ui->command, 5, 0);
    optionsGroupBoxLayout->addWidget(ui->label_5, 6, 0);
    optionsGroupBoxLayout->addWidget(ui->label_6, 7, 0);
    optionsGroupBoxLayout->addWidget(ui->add_argument, 8, 1);
    optionsGroupBoxLayout->addWidget(ui->rmButton, 9, 1);
    optionsGroupBoxLayout->addWidget(ui->clear, 10, 1);
    optionsGroupBoxLayout->addWidget(ui->listWidget, 8, 0, 3, 1);
    optionsGroupBox->setLayout(optionsGroupBoxLayout);
    }

    void custom_command::createButtonsLayout()
    {
    buttonsLayout = new QHBoxLayout;
    buttonsLayout->addWidget(ui->help);
    buttonsLayout->addStretch();
    buttonsLayout->addWidget(ui->cancel);
    buttonsLayout->addWidget(ui->test);
    buttonsLayout->addWidget(ui->apply);
    }@

    And i use ->hide and ->show to work with the checkbox



  • You could use QPropertyAnimation and animate resizion of the whole dialog. You could save the geometry before it expands into the animation.



  • Yeah but i can't resize it.. I have noooo idead why i can't resize it:

    @if(!this->isMaximized())
    this->resize(QSize(this->width(),this->height()-200));@

    The reason must be something about the groubox.. Anyone can give me a hint?



  • so you cannot resize it from CPP and also by mouse?



  • You should take a look at shape-changing dialogs in C++ GUI Programming with Qt4 Second Edition. ;)



  • I had a similar problem that I solved by inserting a vertical spacer item in between (in your case) the "Show Details" button and the details you're showing. In other words

    //-------------------informative text here -------------------//
    //
    //

    Show Details
    //----------------------vertical spacer----------------------//
    // Command...etc etc etc
    // Help and other buttons

    I then connected the "Show Details" button clicked() signal to a slot that simply hides or shows the widget containing the information that should be visible/not visible.

    Something like:

    @
    void Widget::toggleVisibility()
    {
    if( customComand->isVisible() )
    {
    customComand->hide();
    showDetailsButton->setArrowType( Qt::DownArrow );
    } else {
    customComand->show();
    showDetailsButton->setArrowType( Qt::RightArrow );
    }
    }
    @

    I hope this makes sense.



  • Take a look at the Extension Example in Qt Assistant. The resizing magic is:

    @
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    @



  • well i read "shape-changing dialogs in C++ GUI Programming with Qt4 Second Edition"
    and it solved my problem :)

    i just had to make a second groubox which consisted the widgets that i wanted to hide/show..
    Thank you for your answers! :)



  • Maybe I should take a look at "Shape-changing dialogs in C++ GUI Programming with Qt4 Second Edition" also! :)


Log in to reply
 

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