QML TextField: background Property Works Correctly on Linux but Produces Errors on Windows
-
Hi, I am working on a UI project that is intended to run on both Linux and Windows. In terms of architecture, I am using C++ on the backend side and QML on the frontend side.
My system setup is as follows:
- Linux system:
- Ubuntu 22.04
- I am using Qt 6.8. To enforce this, I call qt_standard_project_setup(REQUIRES 6.8) in my CMake file.
- Windows system:
- Windows 11
- I am also using Qt 6.8 here.
On the QML side, I have the following TextField definition:
import QtQuick.Controls 2.5 TextField { id: textField width: parent.width - label.width - row.spacing height: parent.height placeholderText: lgcTextInput.placeHolderText text: lgcTextInput.text color: "black" font.pixelSize: lgcTextInput.fontPixelSize validator: (lgcTextInput.inputType === "int") ? intVal : null background: Rectangle { color: lgcTextInput.backgroundcolor border.color: lgcTextInput.borderColor border.width: lgcTextInput.borderWidth radius: lgcTextInput.borderRadius } onTextChanged: { if (lgcTextInput.inputType === "double") { const normalized = lgcTextInput.normalizeDoubleInput(text); if (normalized !== text) text = normalized; } lgcTextInput.text = text; lgcTextInput.valueChanged(text); } onEditingFinished: { if (lgcTextInput.inputType === "int") { var v = parseInt(text); if (isNaN(v)) { text = ""; return; } v = Math.max(intVal.bottom, Math.min(intVal.top, v)); text = String(v); } else if (lgcTextInput.inputType === "double") { var s = lgcTextInput.normalizeDoubleInput(text); var d = parseFloat(s); if (isNaN(d)) { text = ""; return; } d = Math.max(lgcTextInput.minValue, Math.min(lgcTextInput.maxValue, d)); text = String(d); } } }On Linux, the application runs without any warnings or errors.
However, on Windows I get the following warning at runtime:QML QQuickRectangle: The current style does not support customization of this control (property: "background" item: QQuickRectangle(0x2359ffd2f20, parent=0x0, geometry=0,0 0x0)). Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-referenceFrom the documentation, I can see that the background property is supposed to be customizable. What I don’t fully understand is why this code works without any warnings on Linux, but produces a style-related warning on Windows.
What is the root cause of this warning?
What style should I use, or what should I change in my QML code on Windows to be able to use the background property without this warning?Any guidance would be appreciated.
Thanks.
-
https://doc.qt.io/qt-6/qtquickcontrols-customize.html#customization-reference
Note: The macOS and Windows styles are not suitable for customizing. It is instead recommended to always base a customized control on top of a single style that is available on all platforms, e.g Basic Style, Fusion Style, Imagine Style, Material Style, Universal Style. By doing so, you are guaranteed that it will always look the same, regardless of which style the application is run with. To learn how to use a different style, see Using Styles in Qt Quick Controls. Alternatively, you can create your own style.
If you want to customize a control the best way is to do an explicit style import (
import QtQuick.Controls.Basicfor example vsimport QtQuick.Controls). -
S serkan_tr has marked this topic as solved