Hide Menu Items in QML



  • Hi,

    I had my gui with menu items like file,tools,settings etc.
    I want to hide one of the menuitem in that, so how to hide it.

    Please give me the solution.

    Thanks in advance


  • Qt Champions 2016

    @DivyaMuthyala I only worked with QtQuickControls2 MenuItems.
    You cannot make the MenuItiem invisible.
    I have some situations, where Menus are created dynamically (depends from context and user-policies / rights)
    thx to a tip @jpnurmi I manage this with a Repeater.
    Use a data model with text and a ID - then you can create the MenuItem from the model and onTriggered(){if id == 42 doSomething(), ...}
    Hope this gives you an idea
    Menu { Repeater { .... } }



  • Qt Quick Controls 2 Menu presents its items using a ListView from Qt Quick, which unfortunately doesn't support hiding items. As a workaround, the height of a hidden list item can be set to 0, though.



  • @DivyaMuthyala
    MenuItems do have visible property which you can set based on your requirement.

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem { text: qsTr("&Open"); visible: false }
            MenuItem { text: qsTr("Exit"); visible: false }
        }
    }


  • Hi pradeep,

    Thanku for your answer, its very helpful.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.