Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
QListWidget detect Scrollbars visibility
the_ last edited by the_
Is there an easy way to read if a vertical or horizontal scrollbar is visible?
if i try
// QListWidget *list exists and has several items qDebug() << list->verticalScrollBar()->isVisible();
i always get false, even if the Scrollbar is visible.
Any hints what i done wrong?
typo in Code
jpalbertini last edited by
How about something like this:
We got the same problem, still don't know the difference though
when/where do you call this code?
I tryed that, it says true, so this region is empty
I call it after adding items to the list to cut off long text to avoid horizontal scroll bars.
right after adding the items?
If yes the view most probably hasn't reacted on it yet. So either you do your check when the view layouts or you force the view to layout before calling your code which checks the scrollbar visibility.
Probably the most easiest way to force a relayout of QScrollAreas children (scrollbars, viewport, etc) is:
QEvent event( QEvent::LayoutRequest ); QApplication::sendEvent( listView, &event ); // check the scrollbar visibility here afterwards
yes i tried it right after adding the list items.
As i figured out, this does not work if you add items to a QListWidget that is already visible. Adding items and then set the widget visible returns then correct values.
Triggering a relayout did not work for me when the widget is already visible.