scrollbar in QGroupBox



  • Hi,

    I want to add scrollbar in QGroupbox, how to do it, Can you please guide me?
    Scrollbar should appear when groupbox is minimized.

    Please suggest me, Thanks in advance.


  • Moderators

    @Apeksha
    simply use a QScrollArea



  • Hi raven-worx,

    Yes I am using Scrollarea, but i need scrollbar when my gui has minimized. suppose my widget is of size 500x500, when it is minized, suppose to 300x200 then only scrollbar should appear. I hope you got my point.


  • Moderators

    @Apeksha
    isn't that the default behavior of QScrollArea anyways?!



  • Hi raven-worx,

    Actually my requirement is, I have to add scrollbar to groupbox and it should visible when it is minimized.

    Please help me.
    Thanks in advance.


  • Moderators

    @Apeksha said in scrollbar in QGroupBox:

    Actually my requirement is, I have to add scrollbar to groupbox and it should visible when it is minimized.

    yes i got that. And again, this is what QScrollArea already does by default.
    So maybe you can post a screenshot of your issue.

    Maybe you want to use scrollArea->setWidgetResizeable( true ) but still set a minimum size of the content-widget inside the scroll area. When the scroll area gets smaller than the minimum size the scrollbars will be shown. If it is bigger then the specified minimum-size the widget will be resized and use the extra space.

    Is that what you want?



  • Hi raven-worx,

    QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
    QScrollArea* scrollArea = new QScrollArea();
    scrollArea->setStyleSheet("QScrollArea {background-color:gray;}");
    ConfigurationLayout->addWidget(ui->configurationBox);////ui->configurationbox is QGroupBox.
    mainBoxLayout->addLayout(ConfigurationLayout);
    

    This is correctway or anything wrong I am doing.


  • Moderators

    @Apeksha
    you dont add any widget to the scroll-area, i dont see any group-box widget and i don't see any setWidgetResizable() call.
    Hard to say if you are doing all right, when you just post half of the code.



  • QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
    QScrollArea *scrollArea = new QScrollArea;
    scrollArea->setStyleSheet("QScrollArea {background-color:gray;}");
    // ui->scrollArea->widgetResizable(true);
    // scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    // scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    scrollArea->setWidget(ui->configurationBox);
    ConfigurationLayout->addWidget(ui->configurationBox);
    scrollArea->setWidgetResizable(true);
    // ConfigurationLayout->addWidget(ui->scrollArea);
    mainBoxLayout->addLayout(ConfigurationLayout);


  • Moderators

    @Apeksha
    so still no setMinimumSize() call...
    Beside that, are there any questions left from your side?!



  • Hi

    I am little bit confusing, Can you please post lines of code.


  • Moderators

    @Apeksha

    QWidget* contentWidget = ...
         contentWidget->setMinimumSize( 500,500 );
    
    QScrollArea *scrollArea = new QScrollArea;
        scrollArea->setStyleSheet("QScrollArea {background-color:gray;}");
        scrollArea->setWidget( contentWidget );
        scrollArea->setWidgetResizable(true);
    
    QVBoxLayout* groupBoxLayout = new QVBoxLayout;
          groupBoxLayout->addWidget( scrollArea );
    QGroupBox* groupBox = ...
          groupBox->setLayout( groupBoxLayout );
    


  • QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
    QScrollArea *scrollArea = new QScrollArea;
    scrollArea->setStyleSheet("QScrollArea {background-color:rgb(215,214,213);}");
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    scrollArea->setWidget(ui->configurationBox);
    //ConfigurationLayout->addWidget(ui->configurationBox);
    scrollArea->setWidgetResizable(true);
    scrollArea->setMinimumSize(811,50);
    ConfigurationLayout->addWidget(scrollArea);
    mainBoxLayout->addLayout(ConfigurationLayout);


  • Moderators

    @Apeksha
    yes...and?
    Do you have a question?? Does it work for you or not?!



  • No, when I minimized, scrollbar is not coming.



  • Hi raven-worx,

    Thank you for help, it's working fine.


Log in to reply
 

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