Эдуард НеткачёвMarch 24, 2022, 2:29 p.m.
Выделение нескольких объектов
QML, выделение нескольких элементов мышкой
Приветствую всех.
Не могу разобраться как сделать выделение нескольких элементов с помощью удержания клавиши мыши. Уже разные способы пробовал, но каждый раз какой-то затык.
Вот кусок основной программы main.qml:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.5 ApplicationWindow { visible: true title: qsTr("Selection and Scaling") width: Screen.desktopAvailableWidth*50/100 height: Screen.desktopAvailableHeight*80/100 color: "whitesmoke" property double my_scale: 1.0 Flickable { id: _scrollSetup anchors.fill: parent boundsMovement: Flickable.StopAtBounds // если контент больше видимой области, то при перемещении контента он останавливается на границе контента с видимой областью contentWidth: _сolumn.width*my_scale >parent.width ? (_сolumn.width*my_scale):parent.width contentHeight: _сolumn.height*my_scale >parent.height ? (_сolumn.height*my_scale):parent.height MouseArea { id: _mouseFlickable anchors.fill: parent property point clickPos: "0,0" onWheel: if (wheel.angleDelta.y>0) { my_scale*=1.05; } else { my_scale*=0.95; } // реакция на скролл onClicked: console.log("_mouseFlickable.onClicked"); onPressed: { console.log("_mouseFlickable.onPressed"); clickPos = Qt.point(mouse.x,mouse.y) _rect_select.x=clickPos.x; _rect_select.y=clickPos.y; _rect_select.width=0; _rect_select.height=0; _rect_select.visible=true; } onReleased: { console.log("_mouseFlickable.onReleased"); _rect_select.visible=false; } onEntered: console.log("_mouseFlickable.onEntered"); onExited: console.log("_mouseFlickable.onExited"); onPositionChanged: { _rect_select.x=Math.min(mouse.x,clickPos.x) _rect_select.y=Math.min(mouse.y,clickPos.y) _rect_select.width=Math.abs(clickPos.x-mouse.x) _rect_select.height=Math.abs(clickPos.y-mouse.y) } Column { id: _сolumn anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter scale: my_scale Row { id: _rowUpper MyElement { id: element_1 number: 1 height: 160 width: 160 } MyElement { id: element_2 number: 2 height: 160 width: 160 } MyElement { id: element_3 number: 3 height: 160 width: 160 } MyElement { id: element_4 number: 4 height: 160 width: 160 } } Rectangle { anchors.horizontalCenter: parent.horizontalCenter height: 4 color: "lightsteelblue" width: parent.width } Row { id: _rowLower MyElement { id: element_5 number: 5 height: 160 width: 160 } MyElement { id: element_6 number: 6 height: 160 width: 160 } MyElement { id: element_7 number: 7 height: 160 width: 160 } MyElement { id: element_8 number: 8 height: 160 width: 160 } } } } } Rectangle { id: _rect_select visible: false color: "blue" opacity : 0.3 } }
Вот код элемента MyElement.qml:
import QtQuick 2.0 Item { property int number: 0 property bool select: false MouseArea { id: _mouseArea anchors.fill: parent hoverEnabled: true // это для работы функции containsMouse (наведение курсора мыши на область) propagateComposedEvents: true onClicked: { console.log("_mouse_" + number + ".onClicked"); mouse.accepted = false; } onPressed: { console.log("_mouse_" + number + ".onPressed"); mouse.accepted = false; } onReleased:{ console.log("_mouse_" + number + ".onReleased"); mouse.accepted = false; } onEntered: { console.log("_mouse_" + number + ".onEntered"); } onExited: { console.log("_mouse_" + number + ".onExited"); } Rectangle { id: _rect anchors.fill: parent color: "green" scale: select ? 1.0 : _mouseArea.containsMouse ? 0.95 : 0.90 } } }
Может есть мысли как это сделать.
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!
- Дмитрий
- May 7, 2024, 9:40 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:60points,
- Rating points-1
d
- dsfs
- April 26, 2024, 4:56 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
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, 1:50 a.m.
EVADec. 25, 2023, 10:30 a.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
добавить qlineseries в функции в функции: "GPlotter::addSeries(QString title, QVector &arr)" я вызываю метод setChart(...), я в конструктор передал адрес на QChartView элемент
BlinCTMay 5, 2024, 5:46 a.m.
Best Indian Food Restaurant In Cincinnati OH Ready to embark on a gastronomic journey like no other? Join us at App india restaurant and discover why we're renowned as the Best Indian Food Restaurant In Cincinnati OH . Whether y…
Evgenii LegotckoiMay 2, 2024, 2:07 p.m.
IscanderCheApril 30, 2024, 4:22 a.m.
Как вариант, считать пересечение объектов с прямоугольником выделения,
примерный код набрасал: