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. Customizing ScrollBar of QListWidget

Customizing ScrollBar of QListWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetqscrollbarstylesheet
5 Posts 2 Posters 5.2k 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.
  • M Offline
    M Offline
    mounipanditi
    wrote on last edited by mounipanditi
    #1

    Hi Everyone,

    I am trying to customize the scrollbar of QListWidget with my own styleSheet in the following way

    QString styleSheet_string = "QSlider::groove:vertical { border: 1px solid; height: 18px; border-radius: 9px;} QSlider::handle:vertical {width: 18px; background-image: url(:/slider-knob.png)} QSlider::add-page:qlineargradient {background: lightgrey; border-top-right-radius: 9px; border-bottom-right-radius: 9px; border-top-left-radius: 0px;   border-bottom-left-radius: 0px; } QSlider::sub-page:qlineargradient { background: blue; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 9px; border-bottom-left-radius: 9px;} ";
    
    sampleListWidget = new QListWidget(this);
    
    QScrollBar *vBar= sampleListWidget->QAbstractScrollArea::verticalScrollBar();
    qDebug()<<"vBar"<<vBar;
    vBar->setStyleSheet(styleSheet_string);
    
    sampleListWidget->setStyleSheet(
                            "QListWidget {"
                            "border: 0px;"
                            "border-radius: 0px;"
                            "Text-align:center;"
                            "background-color: white;"
                            "}"); 
     sampleListWidget->setGeometry(10,95,200,50);
    //sampleListWidget->setVerticalScrollBar(vBar);
    sampleListWidget->addItem("Hai");
    sampleListWidget->addItem("Hello");
    sampleListWidget->addItem("How");
    sampleListWidget->addItem("are");
    sampleListWidget->addItem("you");
    sampleListWidget->addItem("doing");
    

    I am unable to see any change for the scrollbar in QListWidget

    Please modify my code if there are any mistakes

    Thanks in Advance,
    Mounika.P

    raven-worxR 1 Reply Last reply
    0
    • M mounipanditi

      Hi Everyone,

      I am trying to customize the scrollbar of QListWidget with my own styleSheet in the following way

      QString styleSheet_string = "QSlider::groove:vertical { border: 1px solid; height: 18px; border-radius: 9px;} QSlider::handle:vertical {width: 18px; background-image: url(:/slider-knob.png)} QSlider::add-page:qlineargradient {background: lightgrey; border-top-right-radius: 9px; border-bottom-right-radius: 9px; border-top-left-radius: 0px;   border-bottom-left-radius: 0px; } QSlider::sub-page:qlineargradient { background: blue; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 9px; border-bottom-left-radius: 9px;} ";
      
      sampleListWidget = new QListWidget(this);
      
      QScrollBar *vBar= sampleListWidget->QAbstractScrollArea::verticalScrollBar();
      qDebug()<<"vBar"<<vBar;
      vBar->setStyleSheet(styleSheet_string);
      
      sampleListWidget->setStyleSheet(
                              "QListWidget {"
                              "border: 0px;"
                              "border-radius: 0px;"
                              "Text-align:center;"
                              "background-color: white;"
                              "}"); 
       sampleListWidget->setGeometry(10,95,200,50);
      //sampleListWidget->setVerticalScrollBar(vBar);
      sampleListWidget->addItem("Hai");
      sampleListWidget->addItem("Hello");
      sampleListWidget->addItem("How");
      sampleListWidget->addItem("are");
      sampleListWidget->addItem("you");
      sampleListWidget->addItem("doing");
      

      I am unable to see any change for the scrollbar in QListWidget

      Please modify my code if there are any mistakes

      Thanks in Advance,
      Mounika.P

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @mounipanditi said in Customizing ScrollBar of QListWidget:

      I am unable to see any change for the scrollbar in QListWidget

      because QScrollBar doesn't inherit QSlider (as defined in your stylesheet), thus the style don't get applied.

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

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

        @mounipanditi said in Customizing ScrollBar of QListWidget:

        I am unable to see any change for the scrollbar in QListWidget

        because QScrollBar doesn't inherit QSlider (as defined in your stylesheet), thus the style don't get applied.

        M Offline
        M Offline
        mounipanditi
        wrote on last edited by
        #3

        @raven-worx

        Hi thanks for a quick reply, sorry for that i have replaced QSlider with QScrollBar even though i am unable to see the change.

        Thanks in advance,

        raven-worxR 1 Reply Last reply
        0
        • M mounipanditi

          @raven-worx

          Hi thanks for a quick reply, sorry for that i have replaced QSlider with QScrollBar even though i am unable to see the change.

          Thanks in advance,

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @mounipanditi
          because there is also no (QSlider-related) ::groove sub-element. Where do you have this stylesheet from?!
          See Customizing QScrollBar

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

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

            @mounipanditi
            because there is also no (QSlider-related) ::groove sub-element. Where do you have this stylesheet from?!
            See Customizing QScrollBar

            M Offline
            M Offline
            mounipanditi
            wrote on last edited by
            #5

            @raven-worx

            my bad, Thanks for the link it helped a lot.

            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