Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Customizing ScrollBar of QListWidget



  • 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


  • Moderators

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



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


  • Moderators

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



  • @raven-worx

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