Important: Please read the Qt Code of Conduct -

How to make the ScrollAreaWidgetContents to be adaptive

  • I want to make the size of the scrollAreaWidgetContents can be adaptive so that the QScrollArea can choose whether to display the scroll bar based on the content inside ( e.g. QToolBox, I don't want to display the scroll bar in QToolBox but in QScrollArea).

  • Lifetime Qt Champion


    Can you describe more precisely what kind of widget you are currently building ?

    In any case, are you looking for the widgetResizable property ?

  • Thanks @SGaist .
    Now there is a limited window and I want to show a member list in there by QToolBox. So I use QScrollArea and put the 'QToolBox' in it. Now I want the scroll bar adaptived (value and vision ) when one item in QToolBox was opened and the window can't display all the contens, not need me to set the size of scrollAreaWidgetContents bigger than QScrollArea in advance and the scrollBar's value is fixed.
    the widgetResizable() is true , what should I do.

  • Hi,
    i used it like this.
    According to the status of the chartView scrollArea is or not.
    on header file.
    QChartView * chartView;
    QScrollArea * scroll;

    on cpp file
    chartView = new QChartView();
    scroll = new QScrollArea;

  • Thanks @A-A-SEZEN
    I will try donig that on cpp later,.
    Now I just do that on designer, cus I can promote the widget easily.

  • Lifetime Qt Champion

    I don't understand why you want to put your QToolBox in a QScrollArea. AFAIR, it already handles large content itself showing scroll bars as needed.

  • @SGaist
    Cus I want the scroll bar is a total scroll bar, not the scroll bar of each widget in QToolbox. I think it is a bit unattractive and out of line with user habits.
    Sorry maybe my request is a bit harsh. If it can not achieve this effect, I can make it with buttons and widget in a scroll area, just a bit complicated.
    Thank you~

  • Lifetime Qt Champion

    Can you show an example of the visual you are trying to produce ?

  • Hi @SGaist
    I make a simple picture to show what I want. Each widget in toolbox can show all contents without blank and scrollbar. And if the entire toolbox is out of display in mainwindows(has a scrollarea), it will show the scrollbar (outside the toolbox).
    I have read the source code of QToolBox, there is a QScrollArea in struct Page. I think we can add an attribute about how to show the contents in each page to let designers choose it, and remind the designers make sure the minimum size of each widget in each page. when one tab is clicked, the toolbox will be resized.
    I hope and suggest this attribute will be used in new Qt version, cus I think it is more appropriate.
    Also thanks @mrjj in here.

Log in to reply