CodexBloom - Programming Q&A Platform

QML Rectangle's border not displaying correctly with dynamic width property in Qt 6.5

👀 Views: 35 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-25
Qt QML dynamic-properties

I'm reviewing some code and I'm wondering if anyone has experience with I can't seem to get I'm trying to create a QML application where I dynamically adjust the border width of a `Rectangle` based on user input..... However, I'm working with an scenario where the border does not update visually when I change the width property at runtime. Here's a simplified version of my code: ```qml import QtQuick 2.15 import QtQuick.Controls 2.15 ApplicationWindow { visible: true width: 400 height: 300 Rectangle { id: myRectangle width: 200 height: 200 border.color: 'blue' border.width: borderWidth property int borderWidth: 5 TextField { id: borderWidthInput anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter placeholderText: 'Enter border width' onTextChanged: { borderWidth = parseInt(text) || 0; // Fallback to 0 if input is invalid } } } } ``` The `borderWidth` property does update as expected (I can see its value changing in the debugger), but the visual border doesn't reflect this change. I've tried forcing a repaint by calling `myRectangle.update()` after changing the property, but that didn't help either. I also experimented with setting `border.width` directly in the `onTextChanged` signal, but the scenario continues. I have confirmed that my Qt version is 6.5, and I'm running this on a Windows environment. The Rectangle's fill color updates without scenario, so it seems to be isolated to the border property. Is there something I'm missing regarding property bindings or updates in QML? Any insights would be greatly appreciated! Has anyone dealt with something similar? This is part of a larger application I'm building. Any ideas what could be causing this? I'm coming from a different tech stack and learning Qml. I'm developing on Windows 11 with Qml. Could someone point me to the right documentation?