I'm using Qt 5.10.1 with Qt Creator 4.5.1 and the style property is never available in elements.
For example, as shown here ButtonStyle QML Type , I would like to do:
Button {
text: "A button"
style: ButtonStyle {...}
}
But, I get the error:
Cannot assign to non-existent property "style"
I tried with a rectangle, progressbar and I get the same error.
Edit #1:
I do have all these imports. If the import was missing, I would get the error on ButtonStyle , but the error is on style.
import QtQuick 2.2
import QtQuick.Controls 2.3
import QtQuick.Dialogs 1.0
import QtGraphicalEffects 1.0
import QtQuick.Shapes 1.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4
There are 2 types of Buttons in QML:
In your case, you are importing the Qt QuickControls 2 Button:
import QtQuick.Controls 2.3
, and that Button does not have thestyle
attribute.If you need to use the style you must import:
instead of:
If you are using items from Qt Quick Controls and Qt Quick Controls 2 you could separate them using a namespace:
You can customize
Qt Quick Controls 2
button by modifying its two visual items of background and content item:https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-button
Make sure importing
QtQuick.Controls.Styles