Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pyqt5 support to load_stylesheet() #135

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Please, insert your information after the last one.

- Year - Name - `<contact>` - contribution.

- 2018 - [mowoolli](https://github.com/mowoolli) - bug fixes.
- 2018 - Xingyun Wu - `[email protected]` - bug fixes.
- 2018 - [KcHNST](https://github.com/KcHNST) - bug fixes.
- 2018 - [mowoolli](https://github.com/mowoolli) - bug fixes.
- 2019 - [goanpeca](https://github.com/goanpeca) - bug fixes, improvements, features.
- 2019 - [Matthew-Reynolds](https://github.com/Matthew-Reynolds) - bug fixes.

Thank you all!
63 changes: 26 additions & 37 deletions qdarkstyle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,36 +213,50 @@ def load_stylesheet(pyside=True):
"Set QtPy environment variable to specify the Qt binding insteady.",
PendingDeprecationWarning
)
# Smart import of the rc file

pyside_ver = None
qt_binding_ver = None

# Smart import of the rc file
if pyside:

# Detect the PySide version available
try:
import PySide
qt_binding_ver = 1
except ImportError: # Compatible with py27
import PySide2
pyside_ver = 2
else:
pyside_ver = 1
qt_binding_ver = 2

if pyside_ver == 1:
if qt_binding_ver == 1:
import qdarkstyle.pyside_style_rc
else:
import qdarkstyle.pyside2_style_rc
else:
import qdarkstyle.pyqt_style_rc

# Detect PyQt version available
try:
import PyQt4
qt_binding_ver = 4
except ImportError:
import PyQt5
qt_binding_ver = 5

if qt_binding_ver == 4:
import qdarkstyle.pyqt_style_rc
else:
import qdarkstyle.pyqt5_style_rc

# Load the stylesheet content from resources
if not pyside:
from PyQt4.QtCore import QFile, QTextStream
else:
if pyside_ver == 1:
if pyside:
if qt_binding_ver == 1:
from PySide.QtCore import QFile, QTextStream
else:
from PySide2.QtCore import QFile, QTextStream
else:
if qt_binding_ver == 4:
from PyQt4.QtCore import QFile, QTextStream
else:
from PyQt5.QtCore import QFile, QTextStream

f = QFile(":qdarkstyle/style.qss")
if not f.exists():
Expand Down Expand Up @@ -325,32 +339,7 @@ def load_stylesheet_pyqt5():
"use load_stylesheet()",
PendingDeprecationWarning
)
# Smart import of the rc file
import qdarkstyle.pyqt5_style_rc

# Load the stylesheet content from resources
from PyQt5.QtCore import QFile, QTextStream

f = QFile(":qdarkstyle/style.qss")
if not f.exists():
_logger().error("Unable to load stylesheet, file not found in "
"resources")
return ""
else:
f.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(f)
stylesheet = ts.readAll()
if platform.system().lower() == 'darwin': # see issue #12 on github
mac_fix = '''
QDockWidget::title
{
background-color: #32414B;
text-align: center;
height: 12px;
}
'''
stylesheet += mac_fix
return stylesheet
return load_stylesheet(pyside=False)


def information():
Expand Down