QML module for easy to use the pull-to-refresh feature in Qt Quick.
Note that in version 2.0
some changes happened that you need to update your code, if you want to migrate to version 2.0
:
- All elements moved to the com.melije.pulltorefresh module.
- Project code convention change to the camleCase for better compatibility with QML.
- `flickable` property in `PullToRefreshHandler` renamed to `target`.
Simple |
Refresh indicator |
Swipe up hint |
Qt >= 5.12
- Add the
PullToRefreshHandler.pri
to your project file (.pro
), like the following:
include(Path/to/PullToRefreshHandler.pri)
- Add the
engine.addImportPath("qrc:/");
to themain.cpp
file, beforeengine.load()
call.
-
Add
import com.melije.pulltorefresh 2.0
to yourqml
file. -
Put the
PullToRefreshHandler
component on the flickable element (e.g ListView):
ListView
{
delegate: ItemDelegate
{
text: model.text
width: parent.width
}
PullToRefreshHandler
{
onPullDownRelease:
{
// Add your handling code here:
}
onPullUpRelease:
{
// Add your handling code here:
}
}
}
- signal
pullDown()
- signal
pullUp()
- signal
pullDownRelease()
- signal
pullUpRelease()
target
: Flickable => Target flickable element, default is set to parentthreshold
: int => The threshold of distance changes in the percentage of the parent heightisPullDown
(Readonly): boolisPullUp
(Readonly): boolswipeUpHintDelegate
: Component => Any QML visual item to show when the flickable is scrolled to the end.swipeDownHintDelegate
: Component => Any QML visual item to show when the flickable is scrolled to the beginning.refreshIndicatorDelegate
: Component => Any QML Visual item to show when the flickable is scrolled to down or up, if you do not set this delegate, the default refresh indicator (Matrerial Refresh Indicator like) will show.indicatorDragDirection
: IndicatorDragDirection enum =>indicatorDragDirection
will specify when therefreshIndicator
must be shown, the default value isTOPTOBOTTOM
.
Constant |
---|
TOPTOBOTTOM |
BOTTOMTOTOP |
Any QML visual element can use as the refresh indicator, so you can easily create your custom refresh indicator.
When you set refreshIndicatorDelegate
to your custom refresh indicator, PullToRefreshHandler
will expose the dragProgress
and target
variables to your component so you can represent the progress using the values of these.
a simple example:
PullToRefreshHandler
{
id: pulldown_handler
threshold: 20
refreshIndicatorDelegate: Rectangle {
x: (pulldown_handler.width - width) / 2
color: Qt.rgba(1, 0, 0, (dragProgress / 100))
width: 24
height: 24
radius: width / 2
}
}
For more complex implementation, please read the src/com/melije/pulltorefresh/RefreshIndicator.qml
.
If you want to disable the refresh indicator you must change refreshIndicator.active
to the false.
Please help me to improve the quality of the project, contributions are welcome! :)