From d3a08fe16e6b0a6906647c5e7254efd3d6dafb9f Mon Sep 17 00:00:00 2001 From: Irony <892768447@qq.com> Date: Thu, 27 Dec 2018 16:01:51 +0800 Subject: [PATCH] QProxyStyle --- .settings/org.eclipse.core.resources.prefs | 2 + QProxyStyle/Lib/TabBarStyle.py | 36 ++++++++++++++ QProxyStyle/Lib/__init__.py | 0 QProxyStyle/README.en.md | 0 QProxyStyle/README.md | 10 ++++ QProxyStyle/ScreenShot/TabTextDirection.png | Bin 0 -> 7790 bytes QProxyStyle/TabTextDirection.py | 51 ++++++++++++++++++++ README.md | 3 +- 8 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 QProxyStyle/Lib/TabBarStyle.py create mode 100644 QProxyStyle/Lib/__init__.py create mode 100644 QProxyStyle/README.en.md create mode 100644 QProxyStyle/README.md create mode 100644 QProxyStyle/ScreenShot/TabTextDirection.png create mode 100644 QProxyStyle/TabTextDirection.py 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 0000000000000000000000000000000000000000..401be597d0465fed0de55987d123c7dc921c148f GIT binary patch literal 7790 zcmb7JcRZVG-@if$RrJu(fwaddYL8m2RjsPpv$aZ5S}R(c2py_+TU(8)+It2ut2kB_ zF=MM0Bvyo2Z=CbI=XuWgyw4x+AITrrojdpMx_;kvU3ajKmMY`P3nu{pjB0mp>j41q zqI^8*XelE_ojR@na7n7&zG>i``JbX~m#X~9%@!NxxV%_^yTxBo^EhX(0yof4a4;D+9Pl})Q8`*B<_!_8+{