Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the cursor's shape without using MouseArea?

I looked over the similar threads but it didn't help much.

I'm using QtQuick.Controls.Button in QML and I cannot change the cursor shape when hovering over the button! I want to achieve this without using MouseArea. What can be done? As I looked over the documentation I couldn't find a, say, cursorShape property or similar.

like image 515
Ispas Claudiu Avatar asked Jan 13 '16 08:01

Ispas Claudiu


1 Answers

It is kind of a hack, but you can access the Button's own MouseArea via the __behavior pseudo-private property.

Button {
    text: qsTr("Hello World")
    Component.onCompleted: __behavior.cursorShape = Qt.PointingHandCursor
}

Alternatively, you can very easily create your own improved Button:

import QtQuick 2.3
import QtQuick.Controls 1.2

Button {
    property alias cursorShape: mouseArea.cursorShape

    MouseArea
    {
        id: mouseArea
        anchors.fill: parent
        onPressed:  mouse.accepted = false
    }
}

Note that you may have to explicitly import the QML module where you defined Button in order to overshadow the QtQuick.Controls's Button.

like image 115
Yoann Quenach de Quivillic Avatar answered Oct 14 '22 19:10

Yoann Quenach de Quivillic