QListWidget detect Scrollbars visibility
-
Hi all
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?
Thanks!
//Edit
typo in Code -
Hi all
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?
Thanks!
//Edit
typo in Code@the_
Hi
How about something like this:list->verticalScrollBar()->visibleRegion().isEmpty();
We got the same problem, still don't know the difference though
-
Hi all
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?
Thanks!
//Edit
typo in Code@the_
when/where do you call this code? -
@the_
Hi
How about something like this:list->verticalScrollBar()->visibleRegion().isEmpty();
We got the same problem, still don't know the difference though
I tryed that, it says true, so this region is empty
-
@the_
when/where do you call this code?I call it after adding items to the list to cut off long text to avoid horizontal scroll bars.
-
I call it after adding items to the list to cut off long text to avoid horizontal scroll bars.
@the_
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
-
@the_
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
@raven-worx
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.