pyqt的QToolBar设置样式表
时间: 2024-01-03 22:22:01 浏览: 205
在PyQt中,可以使用样式表来设置QToolBar的外观。以下是一个示例:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction
from PyQt5.QtCore import Qt
app = QApplication([])
window = QMainWindow()
toolbar = QToolBar()
window.addToolBar(toolbar)
action1 = QAction("Action 1", window)
toolbar.addAction(action1)
action2 = QAction("Action 2", window)
toolbar.addAction(action2)
# 设置样式表
toolbar.setStyleSheet("""
QToolBar {
background-color: #f2f2f2;
border: none;
}
QToolButton {
background-color: #ffffff;
border: 1px solid #cccccc;
padding: 5px;
}
QToolButton:hover {
background-color: #e6e6e6;
}
QToolButton:pressed {
background-color: #cccccc;
}
""")
window.show()
app.exec_()
```
这个例子创建了一个带有两个动作的QToolBar,并使用样式表设置了QToolBar和QToolButton的外观。你可以根据需要修改样式表中的属性来自定义外观。
阅读全文
相关推荐

















