[Interest] qtquickcontrols question

Damian Ivanov damianatorrpm at gmail.com
Wed Nov 6 16:49:10 CET 2013


Hi,

I have a question :)
http://blog.qt.digia.com/blog/2011/08/26/toplevel-windows-and-menus-with-qt-quick/

says
 Context Menus

Sometimes it is also nice to have a ContextMenu for certain options.
In that case some javascript certainly needs to be involved.

ContextMenu {
    id: contextMenu
    MenuItem {
        text: "Copy"
        shortcut: "Ctrl+C"
        onTriggered: copy()
    }
    MenuItem {
        text: "Paste"
        shortcut: "Ctrl+V"
        onTriggered: paste()
    }
}
MouseArea {
    anchors.fill: parent
    acceptedButtons: Qt.RightButton
    onPressed: contextMenu.showPopup(mouseX,mouseY)
}


I'm trying to use a ContextMenu inside a Window { } but it is an
unknown type? why? How can I use Menu { } Items inside a Window { } .
I would also use ApplicationWindow but I need quite every option
Window { } provides (modality, window flags and stuff)




import QtQuick 2.1

import QtQuick.Controls 1.0

import QtProcess 0.1

import QtQuick.Window 2.0

Window {

    id: window1


    width: 400

    height: 400

    minimumWidth: 400

    minimumHeight: 400

    title: "child window"

    ContextMenu {

        id: contextMenu

        MenuItem {

            text: "Copy"

            shortcut: "Ctrl+C"

            onTriggered: copy()

        }

        MenuItem {

            text: "Paste"

            shortcut: "Ctrl+V"

            onTriggered: paste()

        }

        MouseArea {

            anchors.fill: parent

            acceptedButtons: Qt.RightButton

            onPressed: contextMenu.showPopup(mouseX,mouseY)

        }

    }

}



>> main.qml:13 ContextMenu is not a type


QQmlComponent: Component is not ready

Error: Your root item has to be a Window.

The program has unexpectedly finished.



Thanks in advance
Damian



More information about the Interest mailing list