Important: Please read the Qt Code of Conduct -

QT Qsplitter disable scrollbar on resizing QLabel

  • I have added 2 QScrollArea-> QLabel in QSplitter. And am displaying video on both of them. And by default, both of them have same size..

    So, when I increase the size of one QLabel by adjusting QSplitter handle, the video takes new allocated space and scales accordingly. However, if I then decrease the size of QLabel, the video would still show up at previous bigger scale and scrollbars would appear.

    I instead want to display video without scrollbars and with whatever scale factor that fits current size.

    How this can be achieved ? Many thanks in advance!!!

    This is my code for displaying image on QLabel

    multiews[0] = ui->QImageLabel_view0;
    multiews[1] = ui->QImageLabel_view1;

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Why are you putting your labels in QScrollArea rather than ni the QSplitter directly ?

  • @SGaist
    I want scroll bars to show up when am zooming in/zooming out image.
    However, when am resizing window by QSplitter handle, I would like video to show up in fittocontents.

  • Lifetime Qt Champion

    Then you have to modify your QScrollArea settings while dragging. See widgetResizable

  • @SGaist
    Thanks a lot for your help.
    I tried your suggestion, Now I have

    void Dialog::on_splitter_2_splitterMoved(int pos, int index)

    And I get desired behaviour only when am dragging splitter. However, scrollbars would again show up after releasing splitter handle.

    Could you please help me solve this weird behaviour.

    Also, may I know how can add ui->QImageLabel_view0->width() variable to watch while debugging. It may help solve the problem.

  • Lifetime Qt Champion

    What are you doing when you release the splitter ?

  • @SGaist
    There is no signal for Qsplitter released.
    I am just refreshing Qlabel image view as shown above.
    The above function gets called when Qtimer timeouts.

    I modified splitterMoved function as follows:
    void Dialog::on_splitter_2_splitterMoved(int pos, int index)
    width = multiews[0]->size().width();
    Now am desired behaviour. The contents of image view would scale properly.
    However, scrollbars would still show up as shown below. And the extra space marked in red belongs to ui->scrollAreaWidgetContents_2.

    May I know how should I update its correctly ?

  • Lifetime Qt Champion

    Resize the widget so that it doesn't require the scroll bar anymore.

  • @SGaist
    I tried very hard. But, still am not satisfied with the implementation. And now am feeling helpless.
    If I set set, fixedsize for QLabel, then scroll bars won't appear if I use zoomout/zoomin.
    My question is why QLabel won't shrink back after changing size through Qsplitter. I tried all the combinations of sizepolicy and nothing has worked so far