org::kde::kirigami::ListItemDragHandle

Search for usage in LXR

org::kde::kirigami::ListItemDragHandle Class Reference
Inheritance diagram for org::kde::kirigami::ListItemDragHandle:

Properties

Item listItem
 
ListView listView
 

Signals

void dropped ()
 
void moveRequested (int oldIndex, int newIndex)
 

Additional Inherited Members

- Public Member Functions inherited from QtQuick.Item
 childAt (x, real y)
 
bool contains (point)
 
 forceActiveFocus ()
 
 forceActiveFocus (reason)
 
bool grabToImage (callback, targetSize)
 
object mapFromGlobal (x, real y)
 
object mapFromItem (item, point p)
 
object mapFromItem (item, real x, real y)
 
object mapFromItem (item, real x, real y, real width, real height)
 
object mapFromItem (item, rect r)
 
object mapToGlobal (x, real y)
 
object mapToItem (item, point p)
 
object mapToItem (item, real x, real y)
 
object mapToItem (item, real x, real y, real width, real height)
 
object mapToItem (item, rect r)
 
 nextItemInFocusChain (forward)
 

Detailed Description

Implements a drag handle supposed to be in items in ListViews to reorder items The ListView must visualize a model which supports item reordering, such as ListModel.move() or QAbstractItemModel instances with moveRows() correctly implemented.

In order for ListItemDragHandle to work correctly, the listItem that is being dragged should not directly be the delegate of the ListView, but a child of it.

It is recommended to use DelagateRecycler as base delegate like the following code:

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.19 as Kirigami
...
id: delegateComponent
Kirigami.AbstractListItem {
contentItem: RowLayout {
Kirigami.ListItemDragHandle {
listView: mainList
onMoveRequested: listModel.move(oldIndex, newIndex, 1)
}
QQC2.Label {
text: model.label
}
}
}
}
ListView {
id: mainList
model: ListModel {
id: listModel
ListElement {
label: "Item 1"
}
ListElement {
label: "Item 2"
}
ListElement {
label: "Item 3"
}
}
//this is optional to make list items animated when reordered
moveDisplaced: Transition {
YAnimator {
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
}
}
delegate: Kirigami.DelegateRecycler {
width: mainList.width
sourceComponent: delegateComponent
}
}
...
Since
2.5

Definition at line 72 of file ListItemDragHandle.qml.

Property Documentation

◆ listItem

Item org::kde::kirigami::ListItemDragHandle::listItem
read

This property holds the delegate that will be dragged around.

This item must be a child of the actual ListView's delegate.

Definition at line 79 of file ListItemDragHandle.qml.

◆ listView

ListView org::kde::kirigami::ListItemDragHandle::listView
read

This property holds the ListView that the delegate belong to.

Definition at line 83 of file ListItemDragHandle.qml.

Member Function Documentation

◆ dropped

void org::kde::kirigami::ListItemDragHandle::dropped ( )
signal

This signal is emitted when the drag operation is complete and the item has been dropped in the new final position.

◆ moveRequested

void org::kde::kirigami::ListItemDragHandle::moveRequested ( int  oldIndex,
int  newIndex 
)
signal

This signal is emitted when the drag handle wants to move the item in the model.

The following example does the move in the case a ListModel is used:

onMoveRequested: listModel.move(oldIndex, newIndex, 1)
Parameters
oldIndexthe index the item is currently at
newIndexthe index we want to move the item to

The documentation for this class was generated from the following file:
QString label(StandardShortcut id)
Item listItem
This property holds the delegate that will be dragged around.
ListView listView
This property holds the ListView that the delegate belong to.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:13:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.