Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Find out when a QScrollArea scrollbar is shown



  • I need to resize content inside a QScrollArea when the scrollbar is being shown due to ScrollBarAsNeeded policy, but there are no show or hide signals for QWidget nor did i find anything useful in QScrollBar or QAbstractSlider.

    What would be the procedure to do something like that ?



  • Just thinking out loud, but what happens when you compare the size of the frame contained in the QScrollArea with the size of the QScrollArea itself? Does the child frame size() return its real size, or the visible size within the ScollArea? Test it and see...


  • Lifetime Qt Champion

    Hi
    If its visible, this seems to return the status fine
    qDebug() << "is there : " << ui->scrollArea->verticalScrollBar()->isVisible();



  • @mrjj I know i can test if it is visible, but it is not what i need here, i need to know when it become visible, to modify the values of some of the QWidget i have inside.



  • @Kent-Dorfman That is not an issue here, i can calculate the size of the area inside fine (that is already what i am doing), my problem is that sometimes there are no scrolbar and sometimes there is, when i calculate the size of my QWidget which is relative to the size of the inside area, i do it when i insert it, but by that point, the scrollbar is not there yet if it were to be.

    What i need is some kind of event that triggers when the scrollbar appears, so i can re-calculate everything.


  • Lifetime Qt Champion

    @reonZ said in Find out when a QScrollArea scrollbar is shown:

    What i need is some kind of event that triggers when the scrollbar appears, so i can re-calculate everything.

    Well, you could use an eventfilter and watch for the showEvent for the scrollbar(s)


Log in to reply