Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML TextField: background Property Works Correctly on Linux but Produces Errors on Windows
Forum Updated to NodeBB v4.3 + New Features

QML TextField: background Property Works Correctly on Linux but Produces Errors on Windows

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 129 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote last edited by
    #1

    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:

    1. 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.
    1. 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-reference
    
    

    From 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.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote last edited by
      #2

      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.Basic for example vs import QtQuick.Controls).

      1 Reply Last reply
      2
      • serkan_trS serkan_tr has marked this topic as solved

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved