Cannot find Qt QML SpinBox minimumValue using QtQuick.Controls 2.1 - qt

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!?

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

How to use Text.ElideMiddle in a Label?

I have a label (shown below) that can display fully qualified file names (including full path).
import QtQml.Models 2.2
import QtQuick.Window 2.2
import QtQuick 2.2
import QtQuick.Controls 1.3
import QtQuick.Controls 2.2 as M2
import QtQuick.Layouts 1.3
ApplicationWindow {
Label {
id: lblSelectedFileId
text: selectedFile
anchors.verticalCenter: parent.verticalCenter
}
}
These file names came become too long to display properly. I would like to accomplish two things:
Learn how to use Text.ElideMiddle to shorten my text.
Learn how to limit the max width of my Label.
I'm sure there is a readily available answer in the documents if I could understand it. Have checked a number of references including these listed below and I still cannot resolve my issues in Python.
Text QML Type | Qt Quick 5.9
https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-text.html#elide-prop
Elide text in TextField | Qt Forum
https://forum.qt.io/topic/92006/elide-text-in-textfield
“text-overflow” for a QLabel - Stack Overflow
“text-overflow” for a QLabel’s text rendering in QT
Elided Label - Qt Wiki https://wiki.qt.io/Elided_Label
As Label inherits from Text then you can use that property in the same way. On the other hand there is no maximum width but you have to set the width that will be taken into account for ellipsis.
Label{
id: lblSelectedFileId
text: selectedFile
anchors.verticalCenter: parent.verticalCenter
elide: Label.ElideMiddle // or Text.ElideMiddle
width: 50
}

QML Button exclusiveGroup property?

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

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