How to add an icon for submenu in Quick Controls 2?



  • Hi All,

    I'm creating a Windows desktop application with Qt Creator 4.8.0 & Qt 5.12. I have no problem adding an icon for a MenuItem since it has an icon.source property. But how should I achieve the same effect for a submenu?

    A Menu component becomes a submenu when it is defined inside the scope of the upper-level Menu component. And at this time it looks like a MenuItem with an arrow on the right side.

    I have read the Customizing Qt Quick Controls 2 Page but found nothing customizable for this purpose of Menu.

    For Quick Controls1 Menu, there is an iconSource property. But it is removed in Quick Controls 2 Menu. So is there a way to do this?

    0_1547021213600_submenu-icons.png

    With Thanks,
    a qml beginner


  • Qt Champions 2018

    @nland ,

    I wrote a short Code as below.
    Do you have the same understanding with what my think?

    ApplicationWindow {
        visible: true
    
        menuBar: MenuBar {
          Menu {
            title: qsTr("Sample-MenuBar")
    
            MenuItem {
              text: qsTr("Sample1")
              iconSource: "img/sc01.png"
            }
    
            Menu {
              title: qsTr("Sample2")
              iconSource: "img/sc02.png"
    
              MenuItem {
                text: qsTr("Sample2-2")
                iconSource: "img/sc02.png"
              }
            }
          }
        }
    
      // .....
    }
    

    0_1547025225703_sc.png



  • @KazuoAsano Thank you for responding me!

    Yes, I understand your code. But I think you are using Qt Quick Controls 1, which has an iconSource property for Menu component. But in my case, I'm using Quick Controls 2 and for the Menu type, only the title can be specified.


Log in to reply
 

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