Serj DemchenkoFeb. 18, 2020, 7:19 a.m.
Перетаскивать item из ListView
Привет , кто -нибудь подскажет как реализовать перетаскивание обьектов из листвью , и как это вообще делается ?
Суть в том ,чтобы при объекта из листвью модели ,знать что за обьект.
Вот примерно код
#include <QApplication> #include <QQmlApplicationEngine> #include <QtQuick> #include <QIcon> #include <QtDebug> #include "Utility/XmlManager.h" #include "ItemClasses/DataObject.h" int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); QIcon appIcon(":/IconSource/title.svg"); app.setWindowIcon(appIcon); QQmlApplicationEngine engine; /* cpp listModel */ QList<QObject*> dataList; dataList.append(new DataObject("Item 1", "red")); dataList.append(new DataObject("Item 2", "green")); dataList.append(new DataObject("Item 3", "blue")); dataList.append(new DataObject("Item 4", "yellow")); engine.rootContext()->setContextProperty("myModel", QVariant::fromValue(dataList)); engine.load(QUrl(QLatin1String("qrc:/QmlPages/main.qml"))); qDebug() << "counts delegate:" << dataList.count(); return app.exec(); }
Drawer { id: expanderComponent width: window.width/3 height: window.height Button{ / ... } /*model */ ListView { anchors { left: parent.left right: parent.right top: closeButton.bottom bottom: parent.bottom } contentHeight: height model: myModel delegate: Rectangle{ height: 25 width: parent.width color: model.modelData.color Text { text: model.modelData.name } } Component.onCompleted: console.log("qml count: " + myModel.length) } }
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
B
- Bogdannn
- March 28, 2024, 5:15 a.m.
C++ - Test 001. The first program and data types
- Result:46points,
- Rating points-6
Last comments
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий КононенкоFeb. 5, 2024, 12:50 p.m.
EVADec. 25, 2023, 9:30 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
Как получить в массив значения из связанной модели? Спасибо, разобрался:))
AC
QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…
Alexandru CodreanuJan. 19, 2024, 10:57 p.m.
BlinCTDec. 27, 2023, 7:57 p.m.
ДмитрийJan. 10, 2024, 3:18 p.m.
Evgenii LegotckoiDec. 12, 2023, 5:48 p.m.