python qt tabwidget 样式
时间: 2023-12-22 11:26:58 浏览: 141
以下是一个简单的Python Qt TabWidget样式的例子:
```python
from PyQt5 import QtWidgets, QtGui, QtCore
class TabWidget(QtWidgets.QTabWidget):
def __init__(self, parent=None):
super(TabWidget, self).__init__(parent)
self.setStyleSheet("""
QTabWidget::pane {
border-top: 2px solid #C2C7CB;
}
QTabBar::tab {
background-color: #C2C7CB;
border: 2px solid #C2C7CB;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
min-width: 8ex;
padding: 2px;
}
QTabBar::tab:selected, QTabBar::tab:hover {
background-color: #F2F3F4;
}
QTabBar::tab:selected {
border-color: #C2C7CB;
}
QTabBar::tab:!selected {
margin-top: 2px;
}
QTabBar::tab:first:selected {
border-top-left-radius: 4px;
}
QTabBar::tab:last:selected {
border-top-right-radius: 4px;
}
QTabBar::tab:only-one {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
""")
self.addTab(QtWidgets.QWidget(), "Tab 1")
self.addTab(QtWidgets.QWidget(), "Tab 2")
self.addTab(QtWidgets.QWidget(), "Tab 3")
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
tab_widget = TabWidget()
tab_widget.show()
sys.exit(app.exec_())
```
阅读全文