https://wiki.archlinux.org/api.php?action=feedcontributions&user=Stas2&feedformat=atomArchWiki - User contributions [en]2024-03-29T15:45:03ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Qt&diff=576466Qt2019-06-27T20:27:19Z<p>Stas2: correction</p>
<hr />
<div>[[Category:Widget toolkits]]<br />
[[ja:Qt]]<br />
[[ru:Qt]]<br />
[[zh-hans:Qt]]<br />
{{Related articles start}}<br />
{{Related|KDE}}<br />
{{Related|Uniform Look for Qt and GTK Applications}}<br />
{{Related|GTK+}}<br />
{{Related articles end}}<br />
[https://www.qt.io/ Qt] is a cross-platform application and widget toolkit that uses standard C++ but makes extensive use of a special code generator (called the [https://doc.qt.io/qt-5.12/moc.html Meta Object Compiler], or ''moc'') together with several macros to enrich the language. Some of its more important features include:<br />
<br />
* Running on the major desktop platforms and some of the mobile platforms.<br />
* Extensive internationalization support.<br />
* A complete library that provides SQL database access, XML parsing, thread management, network support, and a unified cross-platform application programming interface (API) for file handling.<br />
<br />
The Qt framework is the basis of the [[KDE]] software community, as well as other important open source and proprietary applications such as [[VLC]], [[VirtualBox]], [[Mathematica]] and many others.<br />
<br />
== Installation ==<br />
<br />
Qt 5.x is available in the [[official repositories]]. Legacy versions of Qt (4.x and 3.x) are available from the [[AUR]]. They can be [[Pacman|installed]] with the following packages:<br />
<br />
* '''Qt 5.x''' is available in the {{Pkg|qt5-base}} package, with documentation in the {{Pkg|qt5-doc}} package.<br />
* '''Qt 4.x''' is available in the {{AUR|qt4}} package, with documentation on AUR in the {{AUR|qt4-doc}} package.<br />
* '''Qt 3.x''' is available from the AUR in the {{AUR|qt3}} package, with documentation on AUR in the {{AUR|qt3-doc}} package.<br />
<br />
== Default Qt toolkit ==<br />
<br />
By installing {{AUR|qtchooser}} you can make the Qt binaries in {{ic|/usr/bin}} (e.g. ''qmake''), which point to the Qt5 versions by default (e.g. ''qmake-qt5''), point to older versions of those tools (e.g. ''qmake-qt4'' or ''qmake-qt3'') instead.<br />
<br />
{{Warning|{{AUR|qtchooser}} is now in conflict with {{Pkg|qt5-base}}. You can install it in /usr/local if you really need it, but it's not officially supported. See {{Bug|51308}}.}}<br />
<br />
=== Using environment variables ===<br />
<br />
To define the default Qt toolkit, you can create {{ic|QT_SELECT}} [[environment variable]]. For example, to use Qt4, set {{ic|1=QT_SELECT=4}}.<br />
<br />
=== Using configuration files ===<br />
<br />
You can set the default Qt toolkit by creating a symlink {{ic|~/.config/qtchooser/default.conf}} to one of ''.conf'' files in {{ic|/etc/xdg/qtchooser/}} directory. For example, to set Qt4 symlink {{ic|/etc/xdg/qtchooser/4.conf}} to {{ic|~/.config/qtchooser/default.conf}}:<br />
<br />
$ ln -s {{ic|/etc/xdg/qtchooser/4.conf}} {{ic|~/.config/qtchooser/default.conf}}<br />
<br />
== Appearance ==<br />
<br />
=== Qt5 ===<br />
<br />
Qt5 decides the style to use based on what desktop environment is used:<br />
<br />
* In KDE Plasma, it uses the actually selected Qt style. It can be configured using ''KDE System Settings'' (''systemsettings5''), the settings can be found in ''Appearance > Application Style > Widget Style''.<br />
* In Cinnamon, GNOME, MATE, LXDE, Xfce, it uses GTK+ ([[Uniform look for Qt and GTK applications#QGtkStyle|QGtkStyle]]).<br />
* In other desktop environments, it uses Fusion.<br />
<br />
To force a specific style, you can set the {{ic|1=QT_STYLE_OVERRIDE}} [[environment variable]]. Specifically, set it to {{ic|gtk2}} if you want to use the [[GTK+]] theme (Note: you will need to install the Qt style plugins mention below to get the GTK+ style). Qt5 applications also support the {{ic|-style}} flag, which you can use to launch a Qt5 application with a specific style.<br />
<br />
The following styles are included in Qt5: ''Fusion'', ''Windows''. Others can be installed from the official repositories:<br />
<br />
* {{App|Breeze|Artwork, styles and assets for the Breeze visual style for the Plasma Desktop.|https://cgit.kde.org/breeze.git|{{Pkg|breeze}}}}<br />
* {{App|Oxygen|KDE Oxygen style.|https://cgit.kde.org/oxygen.git|{{Pkg|oxygen}}}}<br />
* {{App|QtCurve|A configurable set of widget styles for KDE and Gtk.|https://cgit.kde.org/qtcurve.git|{{Pkg|qtcurve-qt5}}}}<br />
* {{App|Adwaita-Qt|A style to bend Qt applications to look like they belong into GNOME Shell.|https://github.com/MartinBriza/adwaita-qt|{{AUR|adwaita-qt5}}{{Broken package link|package not found}}}}<br />
* {{App|Qt style plugins|Additional style plugins for Qt5, including ''GTK+'', ''Cleanlooks'', ''Motif'', ''Plastique''.|https://code.qt.io/cgit/qt/qtstyleplugins.git|{{Pkg|qt5-styleplugins}}}}<br />
* {{App|Kvantum|customizable SVG-based theme engine with a variety of built-in styles, including imitations of some popular GTK+ themes such as ''Adapta'', ''Arc'', ''Ambiance''|https://github.com/tsujan/Kvantum/tree/master/Kvantum|{{Pkg|kvantum-qt5}}}}<br />
<br />
=== Qt4 ===<br />
<br />
Qt4 application will try to mimic the behavior of the desktop environment they are running on, unless they run into some problems or hard-coded settings.<br />
<br />
* In KDE Plasma, it uses the actually selected Qt style. It can be configured using ''KDE System Settings'' (''systemsettings5''), the settings can be found in ''Appearance > Application Style > Widget Style''.<br />
* In Cinnamon, GNOME, Xfce, it uses GTK+ ([[Uniform look for Qt and GTK applications#QGtkStyle|QGtkStyle]]).<br />
* In other desktop environments, it uses Windows.<br />
<br />
For those who want to change the look and feel of Qt4 applications, the ''Qt Configuration'' (''qtconfig-qt4'') GUI tool is provided by the {{AUR|qt4}} package. It offers a simple interface to configure the appearance of Qt4 applications including style, colors, fonts and some further options.<br />
<br />
{{Note|If you use ''GTK+'' style, then color and font settings will be ignored, and inherited from GTK+ 2.}}<br />
<br />
Qt keeps all its configuration information in {{ic|/etc/xdg/Trolltech.conf}} (system-wide) or {{ic|~/.config/Trolltech.conf}} (user-specific). The file is rather difficult to navigate because it contains a lot of information not related to appearance, but for any changes you can just add to the end of the file and overwrite any previous values (make sure to add your modification under the [Qt] header).<br />
<br />
For example, to change the theme to QtCurve, add:<br />
<br />
{{hc|~/.config/Trolltech.conf|<nowiki><br />
...<br />
[Qt]<br />
style=QtCurve<br />
</nowiki>}}<br />
<br />
The following styles are included in Qt4: ''CDE'', ''Cleanlooks'', ''GTK+'', ''Motif'', ''Plastique'', ''Windows''. Others can be installed from the official repositories or the [[AUR]] (most are written for KDE Plasma Desktop):<br />
<br />
* {{App|Breeze|Artwork, styles and assets for the Breeze visual style for the Plasma Desktop.|https://cgit.kde.org/breeze.git|{{AUR|breeze-kde4}}}}<br />
* {{App|QtCurve|A configurable set of widget styles for KDE and Gtk.|https://cgit.kde.org/qtcurve.git|{{Pkg|qtcurve-qt4}}{{Broken package link|{{aur-mirror|qtcurve-qt4}}}}}}<br />
* {{App|Adwaita-Qt| A style to bend Qt applications to look like they belong into GNOME Shell.|https://github.com/MartinBriza/adwaita-qt|{{AUR|adwaita-qt4}}}}<br />
<br />
=== Qt Style Sheets ===<br />
<br />
An interesting way of customizing the look and feel of a Qt application is using Style Sheets, which are just simple CSS files. Using Style Sheets, one can modify the appearance of every widget in the application.<br />
<br />
To run an application with a different style just execute:<br />
<br />
$ qt_application -stylesheet ''style.qss''<br />
<br />
For more information on Qt Style Sheets see the [https://doc.qt.io/qt-5/stylesheet-reference.html official documentation] or other [http://thesmithfam.org/blog/2009/09/10/qt-stylesheets-tutorial/ tutorials]. As an example Style Sheet see this [http://kde-apps.org/content/show.php/roxydoxy?content&#61;125979 Dolphin modification].<br />
<br />
=== GTK+ and Qt ===<br />
<br />
If you have GTK+ and Qt applications, their looks might not exactly blend in very well. If you wish to make your GTK+ styles match your Qt styles please read [[Uniform look for Qt and GTK applications]].<br />
<br />
=== Configuration of Qt5 apps under environments other than KDE Plasma ===<br />
<br />
Unlike Qt4, Qt5 does not ship a qtconfig utility to configure fonts, icons or styles. Instead, it will try to use the settings from the running desktop environment. In KDE Plasma or GNOME this works well, but in other less popular desktop environments or window managers it can lead to missing icons in Qt5 applications. One way to solve this is to fake the running desktop environment by setting {{ic|1=XDG_CURRENT_DESKTOP=KDE}} or {{ic|GNOME}}, and then using the corresponding configuration application to set the desired icon set.<br />
<br />
Another solution is provided by the {{pkg|qt5ct}} package, which provides a Qt5 QPA independent of the desktop environment and a configuration utility. After installing the package, run {{ic|qt5ct}} to set an icon theme, and set the [[environment variable]] {{ic|1=QT_QPA_PLATFORMTHEME="qt5ct"}} so that the settings are picked up by Qt applications. Alternatively, use {{ic|--platformtheme qt5ct}} as argument to the Qt5 application.<br />
<br />
If the below errors are received, and some icons still do not appear in some of the apps, install {{pkg|oxygen}} and {{pkg|oxygen-icons}}:<br />
<br />
Icon theme "oxygen" not found.<br />
Icon theme "oxygen" not found.<br />
Error: standard icon theme "oxygen" not found!<br />
<br />
== Development ==<br />
<br />
=== Supported platforms ===<br />
<br />
Qt supports most platforms that are available today, even some of the more obscure ones, with more ports appearing every once in a while. For a more complete list see the [[Wikipedia:Qt_(framework)#Platforms|Qt Wikipedia article]].<br />
<br />
==== Android ====<br />
<br />
First of all, you need an [[Android|Android SDK]] and NDK.<br />
Install SDK {{AUR|android-sdk}} (some tools have been removed) or {{AUR|android-sdk-25.2.5}} and NDK {{AUR|android-ndk-10e}} from [[AUR]] or using [[Android Studio]].<br />
It is highly recommended to install NDK version [https://developer.android.com/ndk/downloads/older_releases.html#ndk-10c-downloads 10e] because of some [https://wiki.qt.io/Qt_for_Android_known_issues known issues].<br />
Next you are going to need Qt 5 for Android. You can install it from [[AUR]] as described below or build it yourself, you can find build instructions on Qt [https://wiki.qt.io/Android wiki] page.<br />
<br />
* {{AUR|android-armv7a-eabi-qt5}} - armeabi-v7a<br />
* {{AUR|android-x86-qt5}} - x86<br />
* {{AUR|android-x86-64-qt5}} - x86_64<br />
<br />
Or you can use a [https://download.qt.io/official_releases/qt/5.11/5.11.1/qt-opensource-linux-x64-5.11.1.run Qt Installer], for a full list see [https://download.qt.io/official_releases/qt/ Official Qt installers].<br />
<br />
=== Tools ===<br />
<br />
The following are official Qt tools:<br />
<br />
* {{App|[[Wikipedia:Qt Creator|Qt Creator]]|A cross-platform IDE tailored for Qt that supports all of its features.|https://doc.qt.io/qtcreator/|{{Pkg|qtcreator}}}}<br />
* {{App|Qt Linguist|A set of tools that speed the translation and internationalization of Qt applications.|https://doc.qt.io/qt-5/qtlinguist-index.html|Qt 5: {{Pkg|qt5-tools}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|Qt Assistant|A configurable and redistributable documentation reader for Qt ''qch'' files.|https://doc.qt.io/qt-5/qtassistant-index.html|Qt 5: {{Pkg|qt5-tools}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|Qt Designer|A powerful cross-platform GUI layout and forms builder for Qt widgets.|https://doc.qt.io/qt-5/qtdesigner-manual.html|Qt 5: {{Pkg|qt5-tools}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|Qt Quick Designer|A visual editor for QML files which supports WYSIWYG. It allows you to rapidly design and build Qt Quick applications and components from scratch.|https://doc.qt.io/qtcreator/creator-using-qt-quick-designer.html|{{Pkg|qtcreator}}}}<br />
* {{App|qmlscene|A tool for loading QML documents that makes it easy to quickly develop and debug QML applications.|https://doc.qt.io/qt-5/qtquick-qmlscene.html|Qt 5: {{Pkg|qt5-declarative}}, Qt 4 QML Viewer: {{AUR|qt4}}}}<br />
* {{App|[[Wikipedia:Qmake|qmake]]|A tool that helps simplify the build process for development project across different platforms, similar to [[Wikipedia:CMake|cmake]], but with fewer options and tailored for Qt applications.|https://doc.qt.io/qt-5/qmake-manual.html|Qt 5: {{Pkg|qt5-base}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|uic|A tool that reads ''*.ui'' XML files and generates the corresponding C++ files.|https://doc.qt.io/qt-5/uic.html|Qt 5: {{Pkg|qt5-base}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|rcc|A tool that is used to embed resources (such as pictures) into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (.qrc) file.|https://doc.qt.io/qt-5/rcc.html|Qt 5: {{Pkg|qt5-base}}, Qt 4: {{AUR|qt4}}}}<br />
* {{App|moc|A tool that handles Qt's C++ extensions (the signals and slots mechanism, the run-time type information, and the dynamic property system, etc.).|https://doc.qt.io/qt-5/moc.html|Qt 5: {{Pkg|qt5-base}}, Qt 4: {{AUR|qt4}}}}<br />
<br />
=== Bindings ===<br />
<br />
Qt has bindings for all of the more popular languages, for a full list see [[Wikipedia:Qt (framework)#Programming language bindings|this list]].<br />
<br />
The following examples display a small 'Hello world!' message in a window.<br />
<br />
==== C++ ====<br />
<br />
* Package: {{Pkg|qt5-base}}<br />
* Website: https://www.qt.io/developers/<br />
* Build: {{ic|g++ $(pkg-config --cflags --libs Qt5Widgets) -fPIC -o hello hello.cpp}}<br />
* Run with: {{ic|./hello}}<br />
<br />
{{hc|hello.cpp|<br />
#include <QApplication><br />
#include <QLabel><br />
<br />
int main(int argc, char **argv)<br />
{<br />
QApplication app(argc, argv);<br />
QLabel hello("Hello world!");<br />
<br />
hello.show();<br />
return app.exec();<br />
}<br />
}}<br />
<br />
==== QML ====<br />
<br />
* Package: {{Pkg|qt5-declarative}}.<br />
* Website: https://doc.qt.io/qt-5/qtquick-qmlscene.html<br />
* Run with: {{ic|qmlscene hello.qml}}<br />
<br />
{{hc|hello.qml|<br />
import QtQuick 2.3<br />
<br />
Rectangle {<br />
id: page<br />
width: 400; height: 100<br />
color: "lightgray"<br />
<br />
Text {<br />
id: helloText<br />
text: "Hello world!"<br />
anchors.horizontalCenter: page.horizontalCenter<br />
anchors.verticalCenter: page.verticalCenter<br />
font.pointSize: 24; font.bold: true<br />
}<br />
}<br />
}}<br />
<br />
==== Python (PyQt) ====<br />
<br />
* Package:<br />
** {{Pkg|python-pyqt5}} - Python 3 bindings<br />
** {{Pkg|python2-pyqt5}} - Python 2 bindings<br />
<br />
* Website: https://riverbankcomputing.com/software/pyqt/intro<br />
* Run with: {{ic|python hello-pyqt.py}} or {{ic|python2 hello-pyqt.py}}.<br />
<br />
{{hc|hello-pyqt.py|<nowiki><br />
import sys<br />
from PyQt5 import QtWidgets<br />
<br />
app = QtWidgets.QApplication(sys.argv)<br />
label = QtWidgets.QLabel("Hello world!")<br />
<br />
label.show()<br />
sys.exit(app.exec_())<br />
</nowiki>}}<br />
<br />
==== Python (PySide2) ====<br />
<br />
* Package:<br />
** {{Pkg|pyside2}} - Python 3 bindings<br />
** {{AUR|python2-pyside2}}{{Broken package link|package not found}} - Python 2 bindings<br />
* Website: https://wiki.qt.io/Qt_for_Python<br />
* Run with: {{ic|python hello-pyside.py}} or {{ic|python2 hello-pyside.py}}<br />
<br />
{{hc|hello-pyside2.py|<nowiki><br />
import sys<br />
from PySide2.QtWidgets import QApplication, QLabel<br />
<br />
app = QApplication(sys.argv)<br />
label = QLabel("Hello world!")<br />
<br />
label.show()<br />
sys.exit(app.exec_())<br />
</nowiki>}}<br />
<br />
==== C# ====<br />
<br />
See [https://gitlab.com/ddobrev/QtSharp QtSharp].<br />
<br />
==== Ruby ====<br />
{{Out of date|needs update for Qt5}}<br />
* Package: {{AUR|kdebindings-qtruby}}{{Broken package link|{{aur-mirror|kdebindings-qtruby}}}}<br />
* Website: http://rubyforge.org/projects/korundum/<br />
* Run with: {{ic|ruby hello.rb}}<br />
<br />
{{hc|hello.rb|<nowiki><br />
require 'Qt4'<br />
<br />
app = Qt::Application.new(ARGV)<br />
hello = Qt::Label.new('Hello World!')<br />
<br />
hello.show<br />
app.exec<br />
</nowiki>}}<br />
<br />
==== Perl ====<br />
{{Out of date|needs update for Qt5}}<br />
* Package: {{AUR|kdebindings-perlqt}}{{Broken package link|{{aur-mirror|kdebindings-perlqt}}}}<br />
* Website: http://code.google.com/p/perlqt4/<br />
* Run with: {{ic|perl hello.pl}}<br />
<br />
{{hc|hello.pl|<nowiki><br />
use QtGui4;<br />
<br />
my $a = Qt::Application(\@ARGV);<br />
my $hello = Qt::Label("Hello World!", undef);<br />
<br />
$hello->show;<br />
exit $a->exec;<br />
</nowiki>}}<br />
<br />
==== Lua ====<br />
<br />
* Package: {{AUR|libqtlua}}{{Broken package link|{{aur-mirror|libqtlua}}}}<br />
* Website: http://www.nongnu.org/libqtlua/<br />
* Run with: {{ic|qtlua hello.lua}}<br />
<br />
{{hc|hello.lua|<nowiki><br />
label = qt.new_widget("QLabel")<br />
<br />
label:setText("Hello World!")<br />
label:show()<br />
</nowiki>}}<br />
<br />
{{Note|QtLua is not designed to develop an application in pure Lua but rather to extend a Qt C++ application using Lua as scripting language.}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== Disable/Change Qt journal logging behaviour ===<br />
<br />
When using [[KDE]] and/or any other Qt [[desktop environment]] debug info may be frequently be logged in the [[systemd journal]].<br />
<br />
Set {{ic|QT_LOGGING_RULES}} as [[environment variable]] to change this behaviour, e.g. to completely disable logging:<br />
<br />
{{hc|/etc/environment|2=<br />
QT_LOGGING_RULES='*=false'<br />
}}<br />
<br />
To disable only debug logging, use {{ic|1=QT_LOGGING_RULES="*.debug=false"}}.<br />
<br />
=== Icon theme is not applied ===<br />
<br />
Since Qt 5.1 SVG support has moved into a module. Since {{Pkg|qt5-base}} does not depend on {{Pkg|qt5-svg}} it may happen that the {{Pkg|qt5-base}} is installed but not {{Pkg|qt5-svg}}. This results in deceptive icon theme behaviour. Since SVG is not supported the icons are silently skipped and the icon theme may seem to be unused. Installing {{Pkg|qt5-svg}} explicitly solves the problem.<br />
<br />
=== Theme not applied to root applications ===<br />
<br />
As the user theme file ({{ic|$XDG_CONFIG_HOME/Trolltech.conf}}), are not read by other accounts, the selected theme will not apply to [[Running_X_apps_as_root|X applications run as root]]. Possible solutions include:<br />
<br />
* Create symlinks, e.g {{bc|# ln -s /home/[username]/.config/Trolltech.conf /etc/xdg/Trolltech.conf}}<br />
* Configure system-wide theme file: {{ic|/etc/xdg/Trolltech.conf}}<br />
* Adjust the theme as root<br />
<br />
=== Qt4 style not respected ===<br />
<br />
If pure Qt4 (non-KDE) applications do not stick with your selected Qt4 style, then you will probably need to tell Qt4 how to find KDE's styles (Oxygen, Phase etc.). You just need to set the [[environment variable]] {{ic|QT_PLUGIN_PATH}}. E.g.:<br />
<br />
QT_PLUGIN_PATH=$HOME/.kde4/lib/kde4/plugins/:/usr/lib/kde4/plugins/<br />
<br />
{{ic|qtconfig-qt4}} should then be able to find your kde styles and everything should look nice again!<br />
<br />
Alternatively, you can symlink the Qt4 styles directory to the KDE4 styles one:<br />
<br />
# ln -s /usr/lib/{kde,qt}4/plugins/styles/''theme_name''<br />
<br />
=== All Qt5-based applications fail to run after Qt5 update ===<br />
<br />
If you get an error similar to<br />
<br />
Qt FATAL: Cannot mix incompatible Qt library (version 0x50900) with this library (version 0x50901)<br />
<br />
then you are most likely using a Qt5 platform theme or style plugin which has not been recompiled against the latest version of Qt5. These usually use Qt private headers which means they depend on an exact version of Qt and not just a matching soname. Figure out which theme/style you are using by checking the {{ic|QT_STYLE_OVERRIDE}} and {{ic|QT_QPA_PLATFORMTHEME}} environment variables, and rebuild the AUR package that provides it.<br />
<br />
== See also ==<br />
<br />
* [https://qt.io/ Official Website]<br />
* [https://doc.qt.io Qt Documentation]<br />
* [https://planet.qt.io Planet Qt]</div>Stas2