QProxyStyle

This commit is contained in:
Irony 2018-12-27 16:01:51 +08:00
parent 151ba3f2d6
commit d3a08fe16e
8 changed files with 101 additions and 1 deletions

View file

@ -1,5 +1,7 @@
eclipse.preferences.version=1
encoding//QAxWidget/\u663E\u793Aword_excel_pdf.py=utf-8
encoding//QProxyStyle/Lib/TabBarStyle.py=utf-8
encoding//QProxyStyle/TabTextDirection.py=utf-8
encoding//QTableView/CopyContent/CopyContent.py=utf-8
encoding//QTableView/CopyContent/__main__.py=utf-8
encoding//QTableWidget/SqlQuery/SqlQuery.py=utf-8

View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年12月27日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: TabBarStyle
@description:
"""
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QProxyStyle
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = "Copyright (c) 2018 Irony"
__Version__ = "Version 1.0"
class TabBarStyle(QProxyStyle):
def sizeFromContents(self, types, option, size, widget):
size = super(TabBarStyle, self).sizeFromContents(
types, option, size, widget)
if types == self.CT_TabBarTab:
size.transpose()
return size
def drawControl(self, element, option, painter, widget):
if element == self.CE_TabBarTabLabel:
painter.drawText(option.rect, Qt.AlignCenter, option.text)
return
super(TabBarStyle, self).drawControl(element, option, painter, widget)

View file

0
QProxyStyle/README.en.md Normal file
View file

10
QProxyStyle/README.md Normal file
View file

@ -0,0 +1,10 @@
# QProxyStyle
## 1、QTabWidget Tab文字方向
[运行 TabTextDirection.py](TabTextDirection.py)
1. 通过 `app.setStyle(TabBarStyle())` 设置代理样式
2. `sizeFromContents` 转置size
3. `drawControl` 绘制文字
![TabTextDirection](ScreenShot/TabTextDirection.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年12月27日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: TestTabWidget
@description:
"""
from PyQt5.QtWidgets import QTabWidget, QLabel, QWidget, QGridLayout
from Lib.TabBarStyle import TabBarStyle
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = "Copyright (c) 2018 Irony"
__Version__ = "Version 1.0"
class TabWidget(QTabWidget):
def __init__(self, *args, **kwargs):
super(TabWidget, self).__init__(*args, **kwargs)
for i in range(10):
self.addTab(QLabel('Tab' + str(i)), str(i))
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QGridLayout(self)
layout.addWidget(TabWidget(self, tabPosition=TabWidget.North), 0, 1)
layout.addWidget(TabWidget(self, tabPosition=TabWidget.South), 2, 1)
layout.addWidget(TabWidget(self, tabPosition=TabWidget.West), 1, 0)
layout.addWidget(TabWidget(self, tabPosition=TabWidget.East), 1, 2)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
app.setStyle(TabBarStyle())
w = Window()
w.show()
sys.exit(app.exec_())

View file

@ -6,7 +6,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
## 目录
| | |
| 分类 | 控件名 |
|:-------|:-------|
| ActiveX | [QAxWidget](QAxWidget)
| 日历 | [QCalendarWidget](QCalendarWidget)
@ -36,6 +36,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
| OpenGL | [QOpenGLWidget](QOpenGLWidget)
| 纯文本 | [QPlainTextEdit](QPlainTextEdit)
| 进度条 | [QProgressBar](QProgressBar)
| 代理样式 | [QProxyStyle](QProxyStyle)
| 按钮 | [QPushButton](QPushButton)
| 单选框 | [QRadioButton](QRadioButton)
| 滚动区 | [QScrollArea](QScrollArea)