I'm writing an application for tablet using QML.
The main QML file of the application is something like this:
ApplicationWindow {
id: mainWindow
visible: true
title: "MyApp"
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Open project")
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
}
If I run the app on an Android device, the menu is styled like a standard Android menu, that is a button (with the "3 points" icon) on the top right corner. This is very good.
Instead if I run the app on a Windows device, the menu is like a standard desktop application menu (the traditional file menu...). This style is not suitable for a tablet application.
There is a way to choose the style of the application?
Thanks!
The correct style should be picked up by default. If it's not, it means that a style for that device type (e.g. touch) isn't available. If you want to use a specific style, you can set the QT_QUICK_CONTROLS_STYLE environment variable before running your application. However, some styles can only be run on the platform they are built for. For example, the Android style needs a specific file from a directory on the device in order to function properly.
Note that Qt Quick Controls have a stronger focus on desktop. If you have the opportunity, and you do not need a native style, I'd recommend trying out Qt Labs Controls. They are more touch-oriented, and have a style that implements Microsoft's Universal Design Guidelines.
They currently have three different styles available, and any style can be used on any platform.
Without styling, components from Qt Quick Controls are supposed have a native look. You can make your own styles for almost all of them, though.
Related
I want to set an icon for the program main window. I found this page https://www.red-lang.org/2016/03/060-red-gui-system.html which says:
Icons and other "resources" are now supported for inclusion in Windows executables. They can be set from Red's main script header, these are the currently supported options:
Icon: file! or block! of files
If no Icon option is specified, a default Red icon will be provided.
I don't get if I need to do it in the program declaration or elsewhere
Red [
needs view
icon %icon1.ico
]
; this doesn't seem to work but it also doesn't break the program
I have also tried putting the icon line in the block defining the view but it is breaking the program.
The right syntax is:
Red [
needs: view
icon: %icon1.ico
]
Also the program needs to be compiled (e.g. red -c -t windows program.red). If the program is launched as a script (do %program.red in red console app) the icon will not be picked up.
I use C++/Qt 5.12, Windows 7 OS, Visual Studio 2017.
I'd like checkable QPushButton background to ignore checked/pressed state. I'd like to have a default background in a QPushButton instance, but only font color should be changed if the user checked the button. How can I achieve this effect?
You can use QSS (CSS with Qt's flavor) to customize QWidgets:
https://doc.qt.io/qt-5/stylesheet-syntax.html
I would recommend creating an application-wide QSS that you load at startup, and use QApplication::setStyleSheet(...). But you can use Qt Designer (right click on a specific control), or plain C++
myButton->setStyleSheet("QPushButton { background: yellow; }");
You may need to redefine border to have it visually applied, and then margins to have a correct button size, but it is fairly easy. Try experimenting from Qt Designer.
You can find a comprehensive reference of all selectors and attributes available here: https://doc.qt.io/qt-5/stylesheet-reference.html
I've just started my adventure with Qt. After installation of QtCreator 3.6.0, the project compiled without any problems, but when I try to change PushButton colour through GUI (palette), nothing happens.
Similarly, when I substitute my own class for just added to work place (containers) widget, there's no file to swap in options. Where's the problem?
You can use CSS styles. Add the following CSS style to styleSheet of your button.
QPushButton{
background-color:yellow
}
Click on the styleSheet property button (...). Then select a menu item "Add gradient/background-color". You can try default cover or create another one.
More detailed info here http://doc.qt.io/qt-4.8/style-reference.html
#Domino Jachas, Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines, according to the Qt Docs.
QPalette palette = ui->pushButton->palette();
palette.setColor(QPalette::ButtonText, Qt::red); // It's ok
palette.setColor(QPalette::Button, Qt::yellow); // but, not ok. Use theme.
ui->pushButton->setPalette(palette);
I'm using a QwtPlot to draw some data in a fairly heavily styled application. I'm using QtCreator as an IDE, and load one stylesheet for the whole program at the start to keep a consistent look and feel across the whole thing using
qApp->setStyleSheet(style);
All the built in controls obey the style I set here, except for my QwtPlot. Currently all I'm doing in the style sheet is trying to set the foreground colour to white with
QwtPlot
{
color: white;
}
But it doesn't work. However, if I specifically chose "set style sheet" on the widget the designer in QT creator, and just put
color: white;
it works.
It seems to me as if the plot isn't inhereting the top level style sheet, or for some reason my naming/syntax is wrong for selecting the plot (though the few references I've found to styling a QwtPlot online do use the same selector as me).
Can anyone help?
I've read the documentation thoroughly and searched the familiar domains like google and stackoverflow for quite some time now. Unfortunately all this without any solutions to be found. So I'm hoping that someone out here might be my savior..
The Situation:
What I am using: PyQt4, Python 2.6, Windows 7
I'm trying to style a QLabel (using a CSS file which I import in my program). The QLabel is in a QListWidgetItem.
So the structure I have is as follows:
QListWidget
+QListWidgetItem
+QLabel
So according to the documentation the way to access the QLabel would be as follows. No problem here.
QListWidget::item QLabel
{
background-color:#000
}
The Problem:
However, I would like the QLabel styling to ONLY change when I hover the QListWidgetItem. Using the following code, the pseudo-state just gets ignored for some reason. The background-color thus gets applied to the QLabels, but it isn't respecting the pseudo state.
QListWidget::item:hover QLabel
{
background-color:#000
}
This situation persists when I run my application stand-alone.
What isn't the solution:
Setting the QLabel pseudo-state to hover won't work because the QListWidgetItem is taller than the QLabel.
Main Question:
Is there a way to change the style properties of the QLabel when, and only when, the QListWidgetItem is hovered and how can this be achieved?
The goal here is to do it ONLY through the css (or qss if you prefer), which is a separate file that gets imported into the program.
Sources:
qss documentation: http://doc.qt.digia.com/4.6/stylesheet-syntax.html
You can't do this at least in Qt 4.7 (did not tested Qt5)
here is good explanation: How to set color of child QLabels while hover parent QFrame with QSS?
it seems that Qt css does not support pseudo-states for descendant elements but original CSS does:
http://codepen.io/anon/pen/olwHs
You should write some code to support such style. Use Enter/LeaveEvent to handle hover and then set style in your code via setStyleSheet()
You may also use dynamic property for that to leave styles in .ui
QLabel[hover="true"] {}
and then set and reset this value in code
Also you may use dynamic property for main widget
[hover="true"] QLabel {}