Qml列表項拖放

ListModel的move(int from, int to, int n)
可以將列表項進行移動
根據鼠標的拖動位置, 可以判斷出需要移動項的序號

                    var lastIndex = listview.indexAt(mousearea.mouseX + listItem.x,
                                                     mousearea.mouseY + listItem.y);
                    if ((lastIndex < 0) || (lastIndex > listModel.rowCount()))
                        return;
                    if (index !== lastIndex){
                        listModel.move(index, lastIndex, 1);
                    }
                    listItem.toIndex = lastIndex;

這裏寫圖片描述

需要完整代碼請訪問QtQuickExamples

聯繫方式:


作者 鄭天佐
QQ 278969898
主頁 http://www.camelstudio.cn/
郵箱 [email protected]
博客 http://blog.csdn.net/zhengtianzuo06/
github https://github.com/zhengtianzuo
QQ羣 199672080

捐贈

覺得分享的內容還不錯, 就請作者喝杯咖啡吧~~

發佈了99 篇原創文章 · 獲贊 74 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章