“This is the 22nd day of my participation in the August Gwen Challenge, for more details: August Gwen Challenge” juejin.cn/post/698796…


Drawer effects with layout, widget, and ScrollArea are as follows:

The idea is to set the scrollArea as a vertical layout, and then add buttons and widgets. When the mouse clicks on the button, hide the widgets and use the vertical layout to achieve natural scaling. Then why use scrollArea as a container, because scrollArea can be implemented when the container space is not enough, Progress bar appears to slide the list, step by step to achieve the following.


Start by dragging a scrollArea and dropping a few buttons and widgets into the scrollArea and setting the scrollArea to a vertical layoutAdd slots for buttons. When the button is clicked, the widget executes setVisible(false), the widget is hidden, and the layout is automatically arranged so that the widget appears to be closed.

bool iswiedet_1=true;

void MainWindow::on_pushButton_5_clicked(a)
{
    if(iswiedet_1==true)
    {
        ui->widget_2->setVisible(false);
        iswiedet_1=false;
        return;
    }
    ui->widget_2->setVisible(true);
    iswiedet_1=true;
}
Copy the code

At this point, the following effect is achieved:Now, we can add the controls to the widgets that we need, but there is one thing that is missing, which is that when the list is filled with the form, the slider automatically appears. ScrollArea can help us, drag the controls into the ScrollArea, and set the ScrollArea to the vertical layout. This is the complete drawer effect.