Home > Software design >  How to change the color of scrollbar handle of QTextBrowser? - PyQt5
How to change the color of scrollbar handle of QTextBrowser? - PyQt5

Time:07-21

I've been looking through Qt documentation and stack overflow on how to change the scrollbar handle color of a QTextBrowser in PyQt5, but I have not been able to find anything. I've also tried looking into styling the scrollbar handle in the QTextBrowser's stylesheet inside Qt Designer, however it seems that there isn't any QScrollBar object in the QTextBrowser that I can reference in the css.

Any tips or suggestions are much appreciated.

CodePudding user response:

To set it using style sheets you can use the setStyleSheet method on the QTextBrowser like this:

textBrowser.setStyleSheet("""
QTextBrowser QScrollBar::handle {
  background-color: #F71;
  border-color: 1px outset #000;
}""")

or you can apply them application wide by setting on the QApplication.setStyleSheet instance.

Here are some examples of how to customize the QScrollBar handle style sheet.

QScrollBar::handle {
    background-color: green;
}
QScrollBar::handle:horizontal {
    background: white;
}
QScrollBar::handle:vertical {
     background: white;
     min-height: 20px;
}

Source : Customizing QScrollBar

  • Related