0

I want to change the way my splitter handle looks in Pyqt5. In the code below, consider self.widg_1 and self.widg_2 to be any two widgets. Using setStyleSheet results in the error: self.my_splitter_handle.setStyleSheet("border: 3px blue") AttributeError: 'NoneType' object has no attribute 'setStyleSheet'

import sys
from PyQt5.QtCore import Qt
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QWidget, QFrame, QLineEdit, QHBoxLayout, QSplitter


class MyMainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 Splitter"
        self.top = 200
        self.left = 500
        self.width = 400
        self.height = 300
        hbox = QHBoxLayout()
        self.widg_1 = QFrame()
        self.widg_1.setFrameShape(QFrame.StyledPanel)
        self.my_splitter = QSplitter(Qt.Horizontal)
        self.widg_2 = QLineEdit()
        self.my_splitter.addWidget(self.widg_1)
        self.my_splitter.addWidget(self.widg_2)
        self.my_splitter.setSizes([200, 200])
        hbox.addWidget(self.my_splitter)
        # Note: splitter handle 0 is always hidden and handle 1 is between the widgets 1 & 2
        self.my_splitter_handle = self.my_splitter.handle(1)
        self.my_splitter_handle.setStyleSheet("background: 3px blue;")
        self.setLayout(hbox)
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.show()


App = QApplication(sys.argv)
window = MyMainWindow()
sys.exit(App.exec())

Note: I just want a decent and prominent looking splitter handle with an arrow or some other marker like the one in the image.

Splitter handle

Kii
  • 9
  • 3
  • Please provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Also note that if you want to color QSplitter handles, you must set the stylesheet to QSplitter and use the `::handle` pseudo selector (for example, `self.my_splitter.setStyleSheet('QSplitter::handle {background: blue; })`) – musicamante Oct 15 '20 at 16:47
  • Thanks @musicamante for pointing out the pseudo selector. I now have a background color. Without the background color, is there a way to get the arrow symbol or the dotted splitter symbol in a different color? – Kii Oct 16 '20 at 09:43

0 Answers0