QMenu: How to customize the menu items of QMenu

后端 未结 1 1104
时光取名叫无心
时光取名叫无心 2020-12-21 12:14

I want to build a dropdown list control with QPushButton and QMenu like below:

QPushButton* menuBt = new QPushButton(\"Please select\");
menuBt->setFlat(t         


        
相关标签:
1条回答
  • 2020-12-21 13:03

    To set the font-family you don't need to put quotes around the Arial. I believe this prevents your style sheet from parsing correctly.

    A side note: at the moment only your menuBt is styled, other buttons will look like default buttons. To change button style for all buttons in the menu, move the style into the setStylesheet() call of the menu like this:

    menu->setStyleSheet("QMenu::item {font-family: Arial; font-size: 13pt; color: #808080; border: 1px solid gray; background-color: rgb(234,234,234);}" +
    "QMenu::item:hover {background-color: rgb(0, 0, 255);}" +
    "QPushButton {font-family: Arial; font-size: 13pt; color: #808080; border: 1px solid gray;padding: 1px 18px 1px 3px;min-width: 6em; background-color: rgb(234,234,234);}");
    

    But if you want only this one button to look different, it is correct to call setStylesheet() on it, but you can omit the selector, like this:

    menuBt->setStyleSheet("font-family: Arial; font-size: 13pt; color: #808080; border: 1px solid gray;padding: 1px 18px 1px 3px;min-width: 6em; background-color: rgb(234,234,234);");
    
    0 讨论(0)
提交回复
热议问题