QML Button exclusiveGroup property? - qt

I'm unable to assign ExclusiveGroup to my checkable buttons.
ExclusiveGroup {
id: group
onCurrentChanged: {
if(current != null) {
console.info("button checked...no!")
current = null
//current.checked = false <--- also this
}
}
}
Column {
width: parent.width
spacing: 0
Button {
id: btnScan
flat: true
text: qsTr("But1")
width: parent.width
checkable: true
exclusiveGroup: group
}
Button {
id: btnWhiteList
flat: true
text: qsTr("But2")
width: parent.width
checkable: true
exclusiveGroup: group
}
}
The documentation states clearly that Button does have exclusiveGroup property http://doc.qt.io/qt-5/qml-qtquick-controls-button.html#exclusiveGroup-prop. However, when I run the example, I get this error:
qrc:/main.qml:48 Cannot assign to non-existent property "exclusiveGroup"
Hovering mouse over "exclusiveGroup" makes a tooltip show up saying: "Invalid property name exclusiveGroup".
I have Qt 5.9.1 installed. Here's my import statements:
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
What am I doing wrong?
Thanks

The reason for your problem is this:
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
You have a Button in both, but they have a different API.
So at first you import the Button from QtQuick.Controls 1.4. Then you import the Button from QtQuick.Controls 2.0. As QML doesn't know, which one you want to use, it will take the one, you imported the last. If you want to be more specific, on which Button you want to use, you can use named imports
import QtQuick.Controls 1.4 as OldCtrl
import QtQuick.Controls 2.0 as NewCtrl
Then you can use Buttons from both versions as you like:
OldCtrl.Button { // from the QtQuick.Controls 1.4 }
NewCtrl.Button { // from the QtQuick.Controls 2.0 }
The documentation you quote is for QtQuick.Controls 1.x, and from there is the imported ExclusiveGroup. So you are trying to mix things from two libraries, that wont work together.
See ButtonGroup for a similar solution for QtQuick.Controls 2.x
For more on the differences and usecases of the both sets of controls read:
http://blog.qt.io/blog/2016/06/10/qt-quick-controls-2-0-a-new-beginning/
https://doc.qt.io/qt-5/qtquickcontrols2-differences.html

Related

QML Dialog positioning in ApplicationWindow

I am finding it impossible to position a Dialog central to my ApplicationWindow in QT 5.12
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
id:mainApplicationWindow
visible: true
height: 500
width: 500
Item {
anchors.centerIn: parent
MainWindowMessageDialog{
id: messageDialog
}
}
Component.onCompleted: {
messageDialog.open()
}
}
With MainWindowMessageDialog.qml
import QtQuick 2.0
import QtQuick.Dialogs 1.2
Dialog {
title: "There seems to be a problem"
standardButtons: StandardButton.Ok
onAccepted: {
this.close()
}
}
Gives me the image below. I've tried adding a fixed z position but nothing seems to shift the Dialog downwards into the window. I've tried MainWindowMessageDialog on its own outside of an Item. Nothing seems to shift it? Am I missing something?
This turned out to be an issue of modality.
https://bugreports.qt.io/browse/QTBUG-82737?jql=text%20~%20%22MessageDialog%22
Adding
modality: Qt.ApplicationModal
Did the trick

QML - Cannot assign to non-existent property "style"

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:
Button Qt Quick Controls 2: https://doc.qt.io/qt-5.10/qml-qtquick-controls2-button.html
Button Qt Quick Controls: http://doc.qt.io/qt-5/qml-qtquick-controls-button.html
In your case, you are importing the Qt QuickControls 2 Button: import QtQuick.Controls 2.3, and that Button does not have the style attribute.
If you need to use the style you must import:
import QtQuick.Controls 1.4
instead of:
import QtQuick.Controls 2.3
If you are using items from Qt Quick Controls and Qt Quick Controls 2 you could separate them using a namespace:
import QtQuick.Controls 2.3 as QQC2
import QtQuick.Controls 1.4 as QQC1
QQC1.Button {
text: "A button"
style: ButtonStyle {...}
}
QQC2.another_item_of_Qt_Quick_Controls2{
}
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
import QtQuick 2.12
import QtQuick.Controls 2.12
Button {
id: control
text: qsTr("Button")
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: control.down ? "#17a81a" : "#21be2b"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
opacity: enabled ? 1 : 0.3
border.color: control.down ? "#17a81a" : "#21be2b"
border.width: 1
radius: 2
}
}
Make sure importing QtQuick.Controls.Styles
import QtQuick.Controls.Styles 1.4
Button {
text: "A button"
style: ButtonStyle {...}
}

Cannot find Qt QML SpinBox minimumValue using QtQuick.Controls 2.1

I got this piece of code:
import QtQuick 2.7
import QtQuick.Controls 1.5
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("spinbox trouble")
SpinBox{
anchors.centerIn: parent
value: 5
minimumValue: 1
maximumValue: 10
}
}
Everything is fine. Now I want to use SwipeView. To use it I need use QtQuick.Controls 2.1. But when I use version 2.1, I cannot find [minimum/maximum]Value in SpinBox.
Questions:
1. What is reason to drop this properties in QtQuick.Controls 2.1?
2. Is there any way to use both SwipeView and SpinBox with [minimum/maximum]Value property?
Looking at the Qt doc I'd say you can use the from and to properties instead of minimumValue and maximumValue!?

QT Quick Control 2 Combobox cannot select Text

This code blocks work fine with import QtQuick.Controls 1.4
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
Rectangle {
property bool isval: true
objectName: "havadurumuCombo"
anchors.fill: parent
ComboBox {
id:havadurumuCombo
model:combohava.datalist
textRole: "value"
width: parent.width
height: parent.height
}
I have changed QtQuick.Controls 1.4 to import QtQuick.Controls 2.0 . I have experienced strance behavior. I choose combobox then drop down with information in model.That is OK. But I cannot choose any text on combobox.If ı select with curson on dropdown menu, then There is no text appears on it after closing dropdown.

Material theme doesn't seem to work in QML

I have a simple QML with an ApplicationWindow, RowLayout and a bunch of Buttons inside. I have applied the Qt Quick Controls 2 Material theme as per the docs, but nothing changed. What's wrong?
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
Material.theme: Material.Dark
Material.accent: Material.Orange
id: window
visible: true
RowLayout {
anchors.horizontalCenter: window.horizontalCenter
anchors.bottomMargin: 32
Button {
text: "A"
}
Button {
text: "B"
}
Button {
text: "C"
}
}
}
Importing QtQuick.Controls.Material 2.0 and setting some Material specific properties do not apply the Material theme. They will be used if the theme is set using one of the methods described here:
http://doc.qt.io/qt-5/qtquickcontrols2-styles.html

Resources