Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change style in PyQt5

Tags:

styles

qt5

pyqt

I am writing a Qt5 application by using PyQt. I would like to understand how to change the style of the entire application.

The old Qt4 calls like:

app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create('Cleanlooks'))

and the suggested method here does nothing.

Are they deprecated? https://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/

Thank you!

like image 469
David Pasquale Avatar asked Aug 29 '16 07:08

David Pasquale


People also ask

Can we use CSS in PyQt5?

one of the coolest feature in PyQt5 is the ability to design themes using the CSS , CSS is an easy way to design awesome themes with easy selectors , we will not talk about the available selectors in PyQt5 because not all the CSS selectors available in PyQt5 but we will take a look at some cool themes made with other ...

How do I change the font in PyQt?

use setFont() : it sets the default font for the target; you can get the current default font using something. font() , then use font. setPointSize() (or setPointSizeF() for float values, if the font allows it) and then call setFont(font) on the target.

Is PyQt good for GUI?

PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools that include platform-independent abstractions for Graphical User Interfaces (GUI), as well as networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.

Why use PySide instead of PyQt?

Advantages of PySide PySide represents the official set of Python bindings backed up by the Qt Company. PySide comes with a license under the LGPL, meaning it is simpler to incorporate into commercial projects when compared with PyQt. It allows the programmer to use QtQuick or QML to establish the user interface.


1 Answers

may be Cleanlooks is no longer available on your system. By QStyleFactory.keys() you can ask the available styles on your system. On Ubuntu 16.04 and pyqt5 i only get:

['Windows', 'GTK+', 'Fusion']

edit:

here you find the qstyleplugin

containing 6 additional styles, you have to compile it by yourself

  1. edit:

on ubuntu 16.04, python3.5 i got it working by installing the styleplugins to QT5 and compile pyqt5 from source against this QT5:

install QT 5.7 by onlineinstaller

in installationdirectory search qmake, in my case /opt/Qt/5.7/gcc_64/bin/qmake

download qtstyleplugin to an arbitrary directory git clone https://code.qt.io/qt/qtstyleplugins.git and install it:

cd qtstyleplugins
/opt/Qt/5.7/gcc_64/bin/qmake # the qmake from the fresh installation
make
make install

now there is a folder „styles“ in /opt/Qt/5.7/gcc_64/plugins/ containing the additional styles.

download sip-source, compile and install it

download pyqt5-source, compile and install it, in the step python3 configure.py provide the qmake from the QT5-Installation by the --qmake-option and look in the output for missing dependencies.

Now the following styles are available:

['bb10dark', 'bb10bright', 'cleanlooks', 'cde', 'motif', 'plastique', 'Windows', 'Fusion']

i got an sip-error:

RuntimeError: the sip module implements API v11.0 to v11.2 but the PyQt5.QtCore module requires API v11.3

to prevent it, run sudo apt-get purge python3-sip before installing sip as described here

like image 88
a_manthey_67 Avatar answered Oct 19 '22 09:10

a_manthey_67