Important: Please read the Qt Code of Conduct -

QML drop and wheel events

  • Hi,

    I wonder how I get the drop event handling in a QDeclarativeView to work.

    I have a MainWindow with an QDeclarativeView and I set the MainWindow to acceptDrops this works fine.
    But now I can't convince my QDeclarativeView to accept drop events.

    this->qml_view = new QDeclarativeView;

    I thought that this could be the way to get this to work but I can't drop files in this view.
    Any ideas what I have to do, to get this to work ?

    By the way, are there any chances that I can implement mouse wheel events in an qml MouseArea ?

    Thanks for help guy ; )

  • [quote author="Schneidi" date="1284671038"]By the way, are there any chances that I can implement mouse wheel events in an qml MouseArea ?[/quote]

    This isn't really possible at the moment -- "QTBUG-7369": tracks this issue. If you need the functionality in the meantime, it should be possible to implement a custom QDeclarativeItem subclass to handle this.


  • Ok the wheel event isn't a real problem, I implemented it in the mainWindow and synch it with the qml environment.

    But a problem is still the fact that I can't drop files to the mainWindow because I have the
    QDeclaritiveView as centralWidget in my main window.

    How do I drop files into the QDeclarativeView ?


    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    this->v = new QDeclarativeView;


    Once I set the QDeclarativeView as central object, I loose the ability to drop files into mainWindow.

  • A mouse up/down can be used in the following code to increment/dec the text value when the cursor is over top the item. What is the best way to make the scroll wheel do the same? Note, I need this for many items on a single screen. With a QDeclarativeItem subclass, would I need to implement the below in C++?

    With the "implement in mainWindow and sync with qml", would this approach work and how does it look from a high level?

    I'm still climbing the QML learning curve, so so looking for a high level overview or a place to start.


    Rectangle {
    id: valuebox
    smooth: true
    anchors.margins: 10
    radius: 10
    property color default_color: "white"
    color: default_color
    property alias text: text.text
    property alias text_color: text.color
    property int default_pixel_size

    Text {
        id: text
        anchors.centerIn: parent; anchors.verticalCenterOffset: -1
        font.pixelSize: parent.width > parent.height ? parent.height * .5 : parent.width * .5
        color: "white"
        style: Text.Sunken
        styleColor: "black"
        smooth: true
    Keys.onUpPressed: {
        text.text = text.text - (-1)
    Keys.onDownPressed: {
        text.text = text.text - 1
    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onEntered: {
            default_pixel_size = text.font.pixelSize
            text.font.pixelSize = default_pixel_size + 5
            parent.color = "yellow"
            valuebox.focus = true
        onExited: {
            text.font.pixelSize = default_pixel_size
            parent.color = default_color
            valuebox.focus = false



Log in to reply