Added qrc file for stylesheets specific resources + a script to compile the qrc to different qt system( qt c++, python qt)

This commit is contained in:
ColinDuquesnoy 2013-03-10 15:23:21 +01:00
parent 8ecb842a25
commit d0b29eb734
4 changed files with 95 additions and 52 deletions

View File

@ -9,33 +9,31 @@ Usage
============ ============
- Download/clone the project next to your main executable (or wherever you find it fits well) - Download/clone the project next to your main executable (or wherever you find it fits well)
- Compile the qrc file for your system and add it to your application. (simply compile_qrc.py script, it will compile the qrc file for use with Qt (c++), PyQt4 and Pyside.
- Load QDarkStyleSheets/style.qss and - Load QDarkStyleSheets/style.qss and
- Format the stylesheet string to give it the correct location (otherwise
resources won't show).
People that don't want to format may replace all "%(location)s/" occurrences in the style.qss file by their own resource
location.
- apply it on your QApplication instance - apply it on your QApplication instance
Here is a quick snippet in python (PySide/PyQt) that shows how to use the Here is a quick snippet in python (PySide) that shows how to use the
stylesheet. stylesheet.
```Python ```Python
def main(): import sys
# create the qt application from PySide import QtGui
app = QApplication() # import the style resources comiled by compile_rc.py
import style_pyside_rc
# Load the stylesheet # create the application and the main window
f = open("QDarkStyleSheet/style.qss","r") app = QtGui.QApplication(sys.argv)
style_sheet = f.read() window = QtGui.QMainWindow()
f.close()
# format style_sheet to get the correct resource path. # setup stylesheet
path = "" # here we use the working directory but it might somewhere else with open("style.qss", 'r') as stylesheet:
style_sheet = style_sheet % {"location":path} app.setStyleSheet(stylesheet.read())
# apply the stylesheet # run
app.setStyleSheet(style_sheet) window.show()
app.exec_()
``` ```
Status: Status:
@ -71,7 +69,6 @@ What still needs to be done:
- QAbstractScrollArea - QAbstractScrollArea
- QSplitter - QSplitter
- QStatusBar - QStatusBar
- QTableView
- QToolBox - QToolBox
Contact information: Contact information:

18
compile_qrc.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python
"""
Compiles the qrc file using rcc, pyside-rcc and pyrcc4.
"""
import os
# Compile for use with Qt (c++)
print("Compiling for Qt: style.qrc -> style.rcc")
os.system("rcc style.qrc -o style.rcc")
# Compile for use with PyQt4
print("Compiling for PyQt4: style.qrc -> style_pyqt_rc.py")
os.system("pyrcc4 style.qrc -o style_pyqt_rc.py")
# Compile for use with PySide
print("Compiling for PySide: style.qrc -> style_pyside_rc.py")
os.system("pyside-rcc style.qrc -o style_pyside_rc.py")

29
style.qrc Normal file
View File

@ -0,0 +1,29 @@
<RCC>
<qresource prefix="qss_icons">
<file>rc/up_arrow_disabled.png</file>
<file>rc/Hmovetoolbar.png</file>
<file>rc/stylesheet-branch-end.png</file>
<file>rc/branch_closed-on.png</file>
<file>rc/stylesheet-vline.png</file>
<file>rc/branch_closed.png</file>
<file>rc/branch_open-on.png</file>
<file>rc/transparent.png</file>
<file>rc/right_arrow_disabled.png</file>
<file>rc/sizegrip.png</file>
<file>rc/close.png</file>
<file>rc/down_arrow.png</file>
<file>rc/Vmovetoolbar.png</file>
<file>rc/left_arrow.png</file>
<file>rc/stylesheet-branch-more.png</file>
<file>rc/up_arrow.png</file>
<file>rc/right_arrow.png</file>
<file>rc/left_arrow_disabled.png</file>
<file>rc/Hsepartoolbar.png</file>
<file>rc/checkbox.png</file>
<file>rc/branch_open.png</file>
<file>rc/Vsepartoolbar.png</file>
<file>rc/down_arrow_disabled.png</file>
<file>rc/undock.png</file>
</qresource>
</RCC>

View File

@ -155,7 +155,7 @@ QScrollBar::handle:horizontal
QScrollBar::sub-line:horizontal QScrollBar::sub-line:horizontal
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/right_arrow_disabled.png); border-image: url(:/qss_icons/rc/right_arrow_disabled.png);
width: 10px; width: 10px;
height: 10px; height: 10px;
subcontrol-position: right; subcontrol-position: right;
@ -164,8 +164,7 @@ QScrollBar::sub-line:horizontal
QScrollBar::add-line:horizontal QScrollBar::add-line:horizontal
{ {
border-image: url(:/qss_icons/rc/left_arrow_disabled.png);
border-image: url(%(location)s/QDarkStyleSheet/rc/left_arrow_disabled.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: left; subcontrol-position: left;
@ -174,7 +173,7 @@ QScrollBar::add-line:horizontal
QScrollBar::sub-line:horizontal:hover,QScrollBar::sub-line:horizontal:on QScrollBar::sub-line:horizontal:hover,QScrollBar::sub-line:horizontal:on
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/right_arrow.png); border-image: url(:/qss_icons/rc/right_arrow.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: right; subcontrol-position: right;
@ -184,7 +183,7 @@ QScrollBar::sub-line:horizontal:hover,QScrollBar::sub-line:horizontal:on
QScrollBar::add-line:horizontal:hover, QScrollBar::add-line:horizontal:on QScrollBar::add-line:horizontal:hover, QScrollBar::add-line:horizontal:on
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/left_arrow.png); border-image: url(:/qss_icons/rc/left_arrow.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: left; subcontrol-position: left;
@ -222,7 +221,7 @@ QScrollBar::handle:vertical
QScrollBar::sub-line:vertical QScrollBar::sub-line:vertical
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/up_arrow_disabled.png); border-image: url(:/qss_icons/rc/up_arrow_disabled.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: top; subcontrol-position: top;
@ -232,7 +231,7 @@ QScrollBar::sub-line:vertical
QScrollBar::add-line:vertical QScrollBar::add-line:vertical
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/down_arrow_disabled.png); border-image: url(:/qss_icons/rc/down_arrow_disabled.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: bottom; subcontrol-position: bottom;
@ -242,7 +241,7 @@ QScrollBar::add-line:vertical
QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/up_arrow.png); border-image: url(:/qss_icons/rc/up_arrow.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: top; subcontrol-position: top;
@ -252,7 +251,7 @@ QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on
QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on
{ {
border-image: url(%(location)s/QDarkStyleSheet/rc/down_arrow.png); border-image: url(:/qss_icons/rc/down_arrow.png);
height: 10px; height: 10px;
width: 10px; width: 10px;
subcontrol-position: bottom; subcontrol-position: bottom;
@ -299,7 +298,7 @@ QCheckBox:disabled
} }
QSizeGrip { QSizeGrip {
image: url(%(location)s/QDarkStyleSheet/rc/sizegrip.png); image: url(:/qss_icons/rc/sizegrip.png);
width: 12px; width: 12px;
height: 12px; height: 12px;
} }
@ -380,7 +379,7 @@ QRadioButton::indicator:hover, QCheckBox::indicator:hover
QCheckBox::indicator:checked QCheckBox::indicator:checked
{ {
image:url(%(location)s/QDarkStyleSheet/rc/checkbox.png); image:url(:/qss_icons/rc/checkbox.png);
} }
QCheckBox::indicator:disabled, QRadioButton::indicator:disabled QCheckBox::indicator:disabled, QRadioButton::indicator:disabled
@ -405,16 +404,16 @@ QToolBar {
} }
QToolBar::handle:horizontal { QToolBar::handle:horizontal {
image: url(%(location)s/QDarkStyleSheet/rc/Hmovetoolbar.png); image: url(:/qss_icons/rc/Hmovetoolbar.png);
} }
QToolBar::handle:vertical { QToolBar::handle:vertical {
image: url(%(location)s/QDarkStyleSheet/rc/Vmovetoolbar.png); image: url(:/qss_icons/rc/Vmovetoolbar.png);
} }
QToolBar::separator:horizontal { QToolBar::separator:horizontal {
image: url(%(location)s/QDarkStyleSheet/rc/Hsepartoolbar.png); image: url(:/qss_icons/rc/Hsepartoolbar.png);
} }
QToolBar::separator:vertical { QToolBar::separator:vertical {
image: url(%(location)s/QDarkStyleSheet/rc/Vsepartoolbars.png); image: url(:/qss_icons/rc/Vsepartoolbars.png);
} }
QPushButton QPushButton
@ -495,13 +494,13 @@ QComboBox::drop-down
QComboBox::down-arrow QComboBox::down-arrow
{ {
image: url(%(location)s/QDarkStyleSheet/rc/down_arrow_disabled.png); image: url(:/qss_icons/rc/down_arrow_disabled.png);
} }
QComboBox::down-arrow:on, QComboBox::down-arrow:hover, QComboBox::down-arrow:on, QComboBox::down-arrow:hover,
QComboBox::down-arrow:focus QComboBox::down-arrow:focus
{ {
image: url(%(location)s/QDarkStyleSheet/rc/down_arrow.png); image: url(:/qss_icons/rc/down_arrow.png);
} }
QPushButton:pressed QPushButton:pressed
@ -534,25 +533,25 @@ QAbstractSpinBox:down-button
} }
QAbstractSpinBox::up-arrow,QAbstractSpinBox::up-arrow:disabled,QAbstractSpinBox::up-arrow:off { QAbstractSpinBox::up-arrow,QAbstractSpinBox::up-arrow:disabled,QAbstractSpinBox::up-arrow:off {
image: url(%(location)s/QDarkStyleSheet/rc/up_arrow_disabled.png); image: url(:/qss_icons/rc/up_arrow_disabled.png);
width: 10px; width: 10px;
height: 10px; height: 10px;
} }
QAbstractSpinBox::up-arrow:hover QAbstractSpinBox::up-arrow:hover
{ {
image: url(%(location)s/QDarkStyleSheet/rc/up_arrow.png); image: url(:/qss_icons/rc/up_arrow.png);
} }
QAbstractSpinBox::down-arrow,QAbstractSpinBox::down-arrow:disabled,QAbstractSpinBox::down-arrow:off QAbstractSpinBox::down-arrow,QAbstractSpinBox::down-arrow:disabled,QAbstractSpinBox::down-arrow:off
{ {
image: url(%(location)s/QDarkStyleSheet/rc/down_arrow_disabled.png); image: url(:/qss_icons/rc/down_arrow_disabled.png);
width: 10px; width: 10px;
height: 10px; height: 10px;
} }
QAbstractSpinBox::down-arrow:hover QAbstractSpinBox::down-arrow:hover
{ {
image: url(%(location)s/QDarkStyleSheet/rc/down_arrow.png); image: url(:/qss_icons/rc/down_arrow.png);
} }
@ -625,8 +624,8 @@ QTabBar::tab:selected:hover
QDockWidget QDockWidget
{ {
color: silver; color: silver;
titlebar-close-icon: url(%(location)s/QDarkStyleSheet/rc/close.png); titlebar-close-icon: url(:/qss_icons/rc/close.png);
titlebar-normal-icon: url(%(location)s/QDarkStyleSheet/rc/undock.png); titlebar-normal-icon: url(:/qss_icons/rc/undock.png);
} }
QDockWidget::title QDockWidget::title
@ -643,8 +642,8 @@ QDockWidget::title
QDockWidget { QDockWidget {
border: 1px solid lightgray; border: 1px solid lightgray;
titlebar-close-icon: url(%(location)s/QDarkStyleSheet/rc/close.png); titlebar-close-icon: url(:/qss_icons/rc/close.png);
titlebar-normal-icon: url(%(location)s/QDarkStyleSheet/rc/undock.png); titlebar-normal-icon: url(:/qss_icons/rc/undock.png);
} }
QDockWidget::close-button, QDockWidget::float-button { QDockWidget::close-button, QDockWidget::float-button {
@ -670,39 +669,39 @@ QTreeView, QListView, QTableView
QTreeView:branch:selected, QTreeView:branch:hover QTreeView:branch:selected, QTreeView:branch:hover
{ {
background: url(%(location)s/QDarkStyleSheet/rc/transparent.png); background: url(:/qss_icons/rc/transparent.png);
} }
QTreeView::branch:has-siblings:!adjoins-item { QTreeView::branch:has-siblings:!adjoins-item {
border-image: url(%(location)s/QDarkStyleSheet/rc/transparent.png); border-image: url(:/qss_icons/rc/transparent.png);
} }
QTreeView::branch:has-siblings:adjoins-item { QTreeView::branch:has-siblings:adjoins-item {
border-image: url(%(location)s/QDarkStyleSheet/rc/transparent.png); border-image: url(:/qss_icons/rc/transparent.png);
} }
QTreeView::branch:!has-children:!has-siblings:adjoins-item { QTreeView::branch:!has-children:!has-siblings:adjoins-item {
border-image: url(%(location)s/QDarkStyleSheet/rc/transparent.png); border-image: url(:/qss_icons/rc/transparent.png);
} }
QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings { QTreeView::branch:closed:has-children:has-siblings {
image: url(%(location)s/QDarkStyleSheet/rc/branch_closed.png); image: url(:/qss_icons/rc/branch_closed.png);
} }
QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings { QTreeView::branch:open:has-children:has-siblings {
image: url(%(location)s/QDarkStyleSheet/rc/branch_open.png); image: url(:/qss_icons/rc/branch_open.png);
} }
QTreeView::branch:has-children:!has-siblings:closed:hover, QTreeView::branch:has-children:!has-siblings:closed:hover,
QTreeView::branch:closed:has-children:has-siblings:hover { QTreeView::branch:closed:has-children:has-siblings:hover {
image: url(%(location)s/QDarkStyleSheet/rc/branch_closed-on.png); image: url(:/qss_icons/rc/branch_closed-on.png);
} }
QTreeView::branch:open:has-children:!has-siblings:hover, QTreeView::branch:open:has-children:!has-siblings:hover,
QTreeView::branch:open:has-children:has-siblings:hover { QTreeView::branch:open:has-children:has-siblings:hover {
image: url(%(location)s/QDarkStyleSheet/rc/branch_open-on.png); image: url(:/qss_icons/rc/branch_open-on.png);
} }
QSlider::groove:horizontal { QSlider::groove:horizontal {