Remove icon space from QMenu

后端 未结 2 1548
深忆病人
深忆病人 2021-01-05 07:12

I\'m working on a Qt application (in C++). Without appyling any styles, my menu looks like this:

I\'d like it to look like this:

How do I a

2条回答
  •  太阳男子
    2021-01-05 07:54

    You can influence on how your menu appears by playing with its style sheet. With you example code you can do the following:

    menu.setStyleSheet("QMenu::item {"
                       "padding: 2px 5px 2px 2px;"
                       "}"
                       "QMenu::item:selected {"
                       "background-color: rgb(0, 85, 127);"
                       "color: rgb(255, 255, 255);"
                       "}");
    

    Note the padding property, which sets the offsets of your menu item rectangles.

提交回复
热议问题