I writting an application with python and PyQt5. I want to styling QToolBar Items with Qt StyleSheet but I can't. I use setStyleSheet metod to do this. I want to set padding for QToolBar Items.
this is my code:
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QToolBar
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QSize
from sys import argv
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.GUI()
def GUI(self):
self.setWindowTitle("test")
self.setFixedSize(640, 480)
self.toolbar = QToolBar("hello")
self.toolbar.setFixedSize(640, 64)
self.addToolBar(self.toolbar)
self.toolbar.setMovable(False)
self.toolbar.setIconSize(QSize(64, 64))
self.newtool = QAction(QIcon("data\\file2.png"), "buutton", self)
self.toolbar.addAction(self.newtool)
self.setStyleSheet("""
QMainWindow {
background: #eee;
}
QToolBar {
background: #eee;
padding: 0px;
border: 0px;
}
QToolBar::item {
background: #59f; # It don't work
padding: 10px; # It don't work
}
""")
if __name__ == "__main__":
app = QApplication(argv)
window = MainWindow()
window.show()
app.exec_()
QTooBar items are QToolButton so you should use that widget:
QToolBar QToolButton{
background-color: #59f;
padding: 10px;
}