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
Forum Updated to NodeBB v4.3 + New Features

Customizing ScrollBar of QListWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetqscrollbarstylesheet
5 Posts 2 Posters 5.3k 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.
  • M Offline
    M Offline
    mounipanditi
    wrote on 19 Mar 2018, 07:09 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

    R 1 Reply Last reply 19 Mar 2018, 07:37
    0
    • M mounipanditi
      19 Mar 2018, 07:09

      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

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 Mar 2018, 07:37 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 19 Mar 2018, 08:25
      1
      • R raven-worx
        19 Mar 2018, 07:37

        @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 19 Mar 2018, 08:25 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,

        R 1 Reply Last reply 19 Mar 2018, 08:29
        0
        • M mounipanditi
          19 Mar 2018, 08:25

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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 19 Mar 2018, 08:29 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 19 Mar 2018, 09:09
          1
          • R raven-worx
            19 Mar 2018, 08:29

            @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 19 Mar 2018, 09:09 last edited by
            #5

            @raven-worx

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

            1 Reply Last reply
            0

            1/5

            19 Mar 2018, 07:09

            • Login

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