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
QtWS25 Last Chance

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.
  • the_T Offline
    the_T Offline
    the_
    wrote on 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 raven-worxR 2 Replies Last reply
    0
    • the_T the_

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

      the_T 1 Reply Last reply
      0
      • the_T the_

        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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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

        the_T 1 Reply Last reply
        0
        • J jpalbertini

          @the_
          Hi
          How about something like this:

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

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

          the_T Offline
          the_T Offline
          the_
          wrote on 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
          • raven-worxR raven-worx

            @the_
            when/where do you call this code?

            the_T Offline
            the_T Offline
            the_
            wrote on 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 --

            raven-worxR 1 Reply Last reply
            0
            • the_T the_

              @raven-worx

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

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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

              the_T 1 Reply Last reply
              1
              • raven-worxR raven-worx

                @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_T Offline
                the_T Offline
                the_
                wrote on 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

                • Login

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