diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index ae7e298..bb8938b 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -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 diff --git a/QProxyStyle/Lib/TabBarStyle.py b/QProxyStyle/Lib/TabBarStyle.py new file mode 100644 index 0000000..f31bc37 --- /dev/null +++ b/QProxyStyle/Lib/TabBarStyle.py @@ -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) diff --git a/QProxyStyle/Lib/__init__.py b/QProxyStyle/Lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/QProxyStyle/README.en.md b/QProxyStyle/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QProxyStyle/README.md b/QProxyStyle/README.md new file mode 100644 index 0000000..bf6f598 --- /dev/null +++ b/QProxyStyle/README.md @@ -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) \ No newline at end of file diff --git a/QProxyStyle/ScreenShot/TabTextDirection.png b/QProxyStyle/ScreenShot/TabTextDirection.png new file mode 100644 index 0000000..401be59 Binary files /dev/null and b/QProxyStyle/ScreenShot/TabTextDirection.png differ diff --git a/QProxyStyle/TabTextDirection.py b/QProxyStyle/TabTextDirection.py new file mode 100644 index 0000000..350a455 --- /dev/null +++ b/QProxyStyle/TabTextDirection.py @@ -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_()) diff --git a/README.md b/README.md index 03b1bdd..e42d6ea 100644 --- a/README.md +++ b/README.md @@ -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)