Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Scroll bar of QListWidget
Forum Updated to NodeBB v4.3 + New Features

Scroll bar of QListWidget

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 6 Posters 15.8k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    hisong1988
    wrote on last edited by
    #1

    Hello, everyone.

    As we know that the scroll bar will appear if there are more items than the list widget could show.

    I don't like the appearance of the scroll bar, so can I inherit the scroll of the QListWidget so that I could customize my own scroll bar?

    and how to do it.

    thanks for suggestions.

    best regards
    hisong.

    I am still searching for....

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

      use QSS

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hisong1988
        wrote on last edited by
        #3

        Hi, Alexander Kuchumov
        would you show me how to define the scroll bar of QListWidget by using QSS.

        or just give me some demo code ? thanks very much.

        I am still searching for....

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AS.Sri
          wrote on last edited by
          #4

          You can use css to change the apperance of the scroll bar. Set the stylesheet for the QListWidget. Here is the link from Qt labs blog "QScrollBar CSS":http://labs.qt.nokia.com/2007/06/12/styling-qprogressbar-and-qscrollbar/

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You can use your own QScrollBar. You can subclass QScrollBar and set it on the QScrollArea that QListWidget inherits. This will allow you to totally develop your own scroll bar, but also makes you have to draw it yourself (depending on how far you customize it).

            There are other ways though. Probably the easiest one is to use Qt's CSS-for-widgets. I guess that what QSS means. The idea is the same as with CSS, only it allows you to style Qt Widgets. There is an "example":http://doc.qt.nokia.com/4.7/stylesheet-examples.html#customizing-qscrollbar in the Qt docs.

            Yet another way is to develop your own (proxy) QStyle. That allows you implement a reusable style implementation for your scroll bar. Another approach is basically not to use QListWidget at all, but use a QAbstractItemModel (or a subclass of that) and use a QML view with a ListView element to completely restyle your view with QML. It doesn't come with a scrollbar at all by default, but it is easy to make one appear as you see fit.

            As you see: there are many options. But since you don't really specify what you really want to achieve, it is hard to give solid guidance. I guess the style sheet option is the best avenue to try first.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              Or simply remember that QListWidget is-a QAbstractScrollArea, so you can set your own QScrollBar with setVerticalScrollBar().

              [edited to add]: Ok, simply wipe out this coment. Andre explained everything very well :-)

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hisong1988
                wrote on last edited by
                #7

                Hi,AS.Sri

                how to indicate the scroll bar of the QListWidget?

                can like this
                @
                listWidget->setStyleSheet(QListWidget::scrollbar{my own code});
                @

                ?

                I am still searching for....

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  [quote author="hisong1988" date="1293021621"]Hi,AS.Sri

                  how to indicate the scroll bar of the QListWidget?

                  can like this
                  @
                  listWidget->setStyleSheet(QListWidget::scrollbar{my own code});
                  @

                  ?[/quote]
                  Did you try reading the documentation on Qt widget style sheets? It has a whole section on selectors you can use.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AS.Sri
                    wrote on last edited by
                    #9

                    As Andre mentioned you can use any selector but,

                    @listWidget->setStyleSheet("selector{my own code}; selector{my own code};............. ");@

                    you don't have to specify QListWidget.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      abah
                      wrote on last edited by
                      #10

                      @QListWidget list = new QListWidget();
                      list->setStyleSheet("
                      {background-color: white; background-image: url(:/Kres/resources/bg01.png); background-attachment: scroll; }");@

                      maybe this would help someone :D

                      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