QML Minimum drag/flick distance for changing item - qt

I have a ListView in QML using theese properties :
ListView {
id : list
boundsBehaviour: Flickable.StopAtBounds
snapMode: PathView.SnapOneItem
highlightFollowsCurrentItem: true
highlightRangeMode: ListView.StrictlyEnforceRange
...
}
My problem is the following :
I'm trying to determine exactly when the drag/flick will made the list move to the next/previous item or staying on the same one when releasing the touch.
Is there a property to modify or something useful to know which behaviour will happen ?
Thanks.

you are looking for startDragDistance property in QApplication class, the default value of startDragDistance is 10 pixels for Windows (it depends on OS)
In order to set drag distance to 50 pixels, you can use the following line
QApplication::setStartDragDistance(50);

Related

How to determine whether a QML component is currently visible on screen

I have a set of controls which have bindings to frequently changing data values. The data comes from a limited hardware-bus. Therefore, it would be better to disable the binding while the control is not visible on screen. The item's visible-property doesn't help in this case. So, how to determine if an Item-based QML widget is currently visible on screen (and not hidden by an overlay or currently outside the visible area)?
Source: https://forum.qt.io/topic/54116/how-to-check-if-a-item-is-currently-visible-on-screen
I have almost the same problem. Hoping someone here has a solution.
Here's what I would try to get working:
First, I presume there is a ScrollView or Flickable in play here? If so, then hook to signals like Flickable::movementEnded().
Second, when that signal fires, use Item::mapToItem() to check if each of your Item's visible rectangle (based on x, y, width, height) intersects your window's contentItem rectangle. Set the result as a boolean on each of your items and make sure the data retrieval is disabled when it is false (using && or a tertiary JS expression).
Or if more convenient, remove the binding when false and reapply it with Qt.binding() when true.

Qt Quick Controls 2: Retrieve standard value of a component

I am making a layout in QML and I want to give my Label the same padding as an ItemDelegate.
How can I get the standard padding value of an ItemDelegate?
Thank you in advance!
Firstly, you'll need an instance of an ItemDelegate. If you don't have one, you can create one and set its visible property to false:
ItemDelegate {
id: itemDelegate
visible: false
}
Some of the built-in styles change as the design guidelines they're based on change, so it's not a good idea to hard-code the padding based on a style's current padding values unless you have control over that style.
In addition, each style sets a different default padding, and may also use different properties to do so. The following properties can be used to control padding, starting with the most general and ending with the most specific:
padding
horizontalPadding (available in Qt 5.12)
verticalPadding (available in Qt 5.12)
leftPadding
rightPadding
topPadding
bottomPadding
Because of this, the only way to guarantee that you'll get the correct padding for each side of the control is to use the most specific properties:
Label {
leftPadding: itemDelegate.leftPadding
rightPadding: itemDelegate.rightPadding
topPadding: itemDelegate.topPadding
bottomPadding: itemDelegate.bottomPadding
}

What's the simplest way to get the currently visible rows (first,last) of a QML TableView?

I need to access currently visible rows (first, last) from a JavaScript function, that is defined inside a TableView.
TableView
{
function getVisibleRows()
{
...
}
}
I see that ListView (what is a Flickable) has a contentY property which would make the problem trivial, but TableView has not. Also, TableView is implemented in terms of a ListView, so there is a ListView involved, but I am not sure how to access it.
Thank You!
I've figured out. I simply need to access flickableItem.contentY.
Use the viewport property of Scrollview (inherited by TableView), which
determines the current "window" on the contentItem. In other words, it
clips it and the size of the viewport tells you how much of the
content area is visible.
viewport return a complete qml item so you can get a lot of position data.

ListView positionViewAtIndex() not working

I have two ListViews in a QML project that are both running off of the same model. I am trying to get them to start out at different indices (the model starts with 2 ListElements in it). In order to do this, I call positionViewAtIndex when the component completes:
ListView {
model: mymodel
Component.onCompleted: positionViewAtIndex(1,ListView.Beginning)
//...
}
However, neither ListView actually is positioned at the desired index. Is there something I'm not doing? The only solution that I have seen for this problem is to ensure that you're not calling the method before the ListView completes, but I am doing that.
I am using Qt 5.2/QtQuick 2.0.
Edit: After playing around with the other positioner functions, I have found that none of them work. I have also found that changing currentIndex does not work either. Furthermore, I have found that currentIndex is not being changed with the view -- onCurrentIndexChanged is never being fired.
So, I figured it out. It turns out that a ListView instantiates its delegates before it worries about its own properties...so the delegate was only reading off of the ListView's width before the ListView set its own dimensions. When a delegate has a width/height property in the orientation of the view equal to zero, the view will not know where to scroll to when positionViewAtIndex() is called. So, in order to fix this, you have to use a conditional binding:
Component {
id: myDelegate
Item {
width: ListView.view.width == 0 ? 480 /*or some preset*/ : ListView.view.width
}
}
This will give the delegate a nonzero width and cause the positionViewAtIndex() function to work.
Of course, if your ListView is vertical, then you need to set the height property and not the width property.
Alternatively you can set currentIndex to 1

QML : If condition in delegate?

I'm designing a spinner list control, which displays 3 items at a time.
Its working fine as required behaviour the only issue am facing is I need the central element appearance little bigger.
The approach which I can think as of now is to have an if condition in the delegate, which on the basis of current index increases the font size.
Is the above approach is possible? Any suggestions to achieve the particular behaviour
Below is the code snippet
SpinnerData {
id: spinner
focus: true
model: 20
delegate: Text { font.pixelSize: spinner.height/4.5; text: index; height: spinner.height }
}
I don't know the details of your component but here you can see implementation of the same control in Qt Quick Components.

Resources