Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget detect Scrollbars visibility
Forum Update on Monday, May 27th 2025

QListWidget detect Scrollbars visibility

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    the_
    wrote on 28 Jan 2016, 08:25 last edited by the_
    #1

    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

    -- No support in PM --

    J R 2 Replies Last reply 28 Jan 2016, 08:28
    0
    • T the_
      28 Jan 2016, 08:25

      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

      J Offline
      J Offline
      jpalbertini
      wrote on 28 Jan 2016, 08:28 last edited by
      #2

      @the_
      Hi
      How about something like this:

      list->verticalScrollBar()->visibleRegion().isEmpty();
      

      We got the same problem, still don't know the difference though

      T 1 Reply Last reply 28 Jan 2016, 08:36
      0
      • T the_
        28 Jan 2016, 08:25

        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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 28 Jan 2016, 08:28 last edited by raven-worx
        #3

        @the_
        when/where do you call this code?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        T 1 Reply Last reply 28 Jan 2016, 08:40
        0
        • J jpalbertini
          28 Jan 2016, 08:28

          @the_
          Hi
          How about something like this:

          list->verticalScrollBar()->visibleRegion().isEmpty();
          

          We got the same problem, still don't know the difference though

          T Offline
          T Offline
          the_
          wrote on 28 Jan 2016, 08:36 last edited by
          #4

          @jpalbertini

          I tryed that, it says true, so this region is empty

          -- No support in PM --

          1 Reply Last reply
          0
          • R raven-worx
            28 Jan 2016, 08:28

            @the_
            when/where do you call this code?

            T Offline
            T Offline
            the_
            wrote on 28 Jan 2016, 08:40 last edited by
            #5

            @raven-worx

            I call it after adding items to the list to cut off long text to avoid horizontal scroll bars.

            -- No support in PM --

            R 1 Reply Last reply 28 Jan 2016, 08:53
            0
            • T the_
              28 Jan 2016, 08:40

              @raven-worx

              I call it after adding items to the list to cut off long text to avoid horizontal scroll bars.

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 28 Jan 2016, 08:53 last edited by
              #6

              @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
              

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              T 1 Reply Last reply 28 Jan 2016, 09:43
              1
              • R raven-worx
                28 Jan 2016, 08:53

                @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
                
                T Offline
                T Offline
                the_
                wrote on 28 Jan 2016, 09:43 last edited by
                #7

                @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.

                -- No support in PM --

                1 Reply Last reply
                0

                3/7

                28 Jan 2016, 08:28

                • Login

                • Login or register to search.
                3 out of 7
                • First post
                  3/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved