How to use QHeaderView in QScrollArea?



  • I have a QScrollArea, which includes a QGroupBox:

    scrollArea = new QScrollArea(&widget);
    groupBoxLayout = new QVBoxLayout();
    groupBox = new QGroupBox();
    
    //add buttons to the layout
    groupBoxLayout->addWidget(buttons[i]);
    
    groupBox->setLayout(groupBoxLayout);
    scrollArea->setWidget(groupBox);
    

    I'm trying to add a fixed header to the layout. A header that will always be visible no matter if I scroll down. So I did this:

    header = new QHeaderView(Qt::Horizontal);
    header->setSectionsMovable(false);
    groupBoxLayout->addWidget(header);
    

    before adding the buttons.

    • The header appears on top of the buttons in the layout but it's empty (of course - I didn't put anything in it).
    • When I scroll down, the header disappears (gets scrolled).
      How do I get it to be fixed? Maybe it needs to not be a part of the scrollarea?

    Thanks


  • Qt Champions 2016

    @AlaaM
    Hello,

    How do I get it to be fixed? Maybe it needs to not be a part of the scrollarea?

    This would be my choice, yes. I'd put the header and the scroll area in a vertical layout (setting the stretches to 0 for the header and 1 for the scroll area) and take it from there.

    Kind regards.


Log in to reply
 

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