Set button color in QML Qt 6.5
-
wrote on 26 Jun 2023, 15:45 last edited by
Hello everyone,
I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :
Button { text: "Test button" palette { button: "green" } }
Does anyone know how to do it in Qt 6.5 ? Thanks in advance
-
Hello everyone,
I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :
Button { text: "Test button" palette { button: "green" } }
Does anyone know how to do it in Qt 6.5 ? Thanks in advance
-
Hello everyone,
I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :
Button { text: "Test button" palette { button: "green" } }
Does anyone know how to do it in Qt 6.5 ? Thanks in advance
wrote on 26 Jun 2023, 22:58 last edited by@Yazid10 to amplify on @JoeCFD 's response:
Button { text: "Text Button" background: Rectangle { anchors.fill: parent color: 'green' } }
BUT:
If you're running on a Mac or Windows box, you'll get a warning about your current style not supporting customization. To fix this, you need something like the following:
main.cpp
#include <QQuickStyle> ... int main(int argc, char *argv[]) { ... QQuickStyle::setStyle("Fusion"); // or whichever you prefer. ...
And the use of QQuickStyle will necessitate an addition to your CMakeLists.txt file.
1/3