1
votes

I am adding a popup menu to my QtQuick GUI (as in here I believe) and it does not behave as I had expected.

Here is what I do:

import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.2

ApplicationWindow
{
    ...

    // File menu button.
    Rectangle
    {
        id: ribbonFileMenuButton
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        width: height
        height: parent.height
        scale: ribbonFileMenuButtonMA.pressed ? 1.3 : 1
        color: "transparent"

        // Icon.
        RibbonFileButtonIcon
        {
            id: ribbonFileMenuButtonIcon
            anchors.fill: parent
        }

        // Behavior.
        MouseArea
        {
            id: ribbonFileMenuButtonMA
            anchors.fill: parent
            onClicked: menu.open() /*popup()*/
        }
    }
    ...

    // File.
    Menu
    {
        id: menu
        y: 20

        MenuItem
        {
            text: "New..."
        }
        MenuItem
        {
            text: "Open..."
        }
//        MenuSeparator { }
        MenuItem
        {
            text: "Save"
        }
    }

...
}

First, I have to call menu.open() and not menu.popup() (as described in the doc indicated in the above provided link): menu.popup() outputs error:

TypeError: Property 'popup' of object QQuickMenu(0x20f40f0) is not a function

Then if I uncomment MenuSeparator { }, I get the following error:

MenuSeparator is not a type

Again, according to the doc in the provided link, it should work.

I have looked over the internet, but I am a bit lost...

Thanks,

Antoine.

1
See if MenuSeparator is available under "import QtQuick.Controls 1.3"?ManuelH
Hum... This regression answers both my questions, This is weird... It seems QtQuick.Controls 2.0 is a complete rewrite which is no fully finished... Am I right?arennuit
I can't say with certainty, but it would help if you stated the exact version of QT you are using. I am currently using 5.4, and the documentation there clearly stated that "MenuSeparator" was available for that QT version and the QtQuick.Controls 1.3 version I told you to try. If you are using a newer QT version than me, which looks likely, then it was very possible that changes were made to that API between QT versions.ManuelH
Using QtQuick.Controls 2.0 as stated in the code (hence Qt 5.7 but I should have mentioned it explicitly, you are right). I believe your explanation is right (and confirmed by @Mitch). Thanks a lot ;)arennuit

1 Answers

2
votes

As @ManuelH said, MenuSeparator isn't available in Qt Quick Controls 2... yet. :)

The 2.0 version is indeed a complete rewrite that brings with it a new API. A lot of the same types are there, but the documentation should be followed closely to avoid relying on API or behaviour from Qt Quick Controls 1.x.

Source compatibility breaks are permitted (though attempted to be kept to a minimum) across major versions (e.g. QtQuick 1.0 to QtQuick 2.0, Qt 4 to Qt 5, etc.).

See this page for more information about the differences between the two APIs, and the blog post that it links to.