Help with Mouse Area and Left and Right Click Selection in Qt Program
-
I am trying to create a program that marks poker hands. I would like to click and drag the mouse over the grid of hands to select them. It would be great if I could use the right mouse button to set the selection back to default (i.e., clear the selection). Is there any solution for the mouse area? Thank you in advance.
Below are some examples of how my program currently looks and how I would like it to be:
import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 GridView { id: gridview property var hands: [] function defaultBg(){ return "lightgray" } function activeBg(){ return "red" } model: hands anchors.horizontalCenter: parent.horizontalCenter cellWidth: width / 13 cellHeight: height / 13 delegate: Rectangle { width: gridview.cellWidth height: gridview.cellHeight border.width: 1 border.color: "#444" color: defaultBg() Text { text: modelData font.pixelSize: 12 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.fill: parent } MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true onEntered: { // if mouse left pressed set color parent.color = activeBg() } onExited: { // if mouse right pressed remove color parent.color = defaultBg() } } } }
-
@supper_DM said in Help with Mouse Area and Left and Right Click Selection in Qt Program:
acceptedButtons: Qt.LeftButton | Qt.RightButton
Hello friend, thank you for your response. I just think that my question was not well understood. I need to click and drag the mouse while clicking and painting the slots as if it were in Excel.
I can do something similar without accepting any mouse button, but inside my "entered" I need it to check the button state if it is left or right pressed.
MouseArea{ anchors.fill: parent // acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.NoButton hoverEnabled: true onEntered: { parent.color = "orange" } onExited: { parent.color = sys.defaultHandBackgroundColor } }