自定义QMenu

参考:

http://blog.csdn.net/qq1623803207/article/details/77449884

http://blog.sina.com.cn/s/blog_a6fb6cc90101fxsc.html

待解决:把QMenu不添加到QMenuBar里就不显示Ctrl+*的这种快捷键提示怎么解决

快捷键能响应还需要把QAction添加到QToolBar里才行。

/*Qmenu Style Sheets*/
 QMenu {
     background-color: white; /* sets background of the menu 设置整个菜单区域的背景色,我用的是白色:white*/
     border: 1px solid white;/*整个菜单区域的边框粗细、样式、颜色*/
 }
  
 QMenu::item {
     /* sets background of menu item. set this to something non-transparent
         if you want menu color and menu item color to be different */
     background-color: transparent;
     padding:8px 32px;/*设置菜单项文字上下和左右的内边距,效果就是菜单中的条目左右上下有了间隔*/
     margin:0px 8px;/*设置菜单项的外边距*/
     border-bottom:1px solid #DBDBDB;/*为菜单项之间添加横线间隔*/
 }
  
 QMenu::item:selected { /* when user selects item using mouse or keyboard */
     background-color: #2dabf9;/*这一句是设置菜单项鼠标经过选中的样式*/
 }
Customizing QMenu

Individual items of a QMenu are styled using the 'item' subcontrol as follows:

QMenu{
background-color:#ABABAB; /* sets background of the menu */
border:1px solid black;
}

QMenu::item {
/* sets background of menu item. set this to something non-transparent
if you want menu color and menu item color to be different */
background-color: transparent;
}

QMenu::item:selected {/* when user selects item using mouse or keyboard */
background-color:#654321;
}

 

For a more advanced customization, use a style sheet as follows:

QMenu{
background-color: white;
margin:2px;/* some spacing around the menu */
}

QMenu::item {
padding:2px25px2px20px;
border:1px solid transparent;/* reserve space for selection border */
}

QMenu::item:selected {
border-color: darkblue;
background: rgba(100,100,100,150);
}

QMenu::icon:checked{/* appearance of a 'checked' icon */
background: gray;
border:1px inset gray;
position: absolute;
top:1px;
right:1px;
bottom:1px;
left:1px;
}

QMenu::separator {
height:2px;
background: lightblue;
margin-left:10px;
margin-right:5px;
}

QMenu::indicator {
width:13px;
height:13px;
}

/* non-exclusive indicator = check box style indicator (see QActionGroup::setExclusive) */
QMenu::indicator:non-exclusive:unchecked{
image: url(:/images/checkbox_unchecked.png);
}

QMenu::indicator:non-exclusive:unchecked:selected {
image: url(:/images/checkbox_unchecked_hover.png);
}

QMenu::indicator:non-exclusive:checked{
image: url(:/images/checkbox_checked.png);
}

QMenu::indicator:non-exclusive:checked:selected {
image: url(:/images/checkbox_checked_hover.png);
}

/* exclusive indicator = radio button style indicator (see QActionGroup::setExclusive) */
QMenu::indicator:exclusive:unchecked{
image: url(:/images/radiobutton_unchecked.png);
}

QMenu::indicator:exclusive:unchecked:selected {
image: url(:/images/radiobutton_unchecked_hover.png);
}

QMenu::indicator:exclusive:checked{
image: url(:/images/radiobutton_checked.png);
}

QMenu::indicator:exclusive:checked:selected {
image: url(:/images/radiobutton_checked_hover.png);
}

 

Customizing QMenuBar

QMenuBar is styled as follows:

QMenuBar{
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 lightgray, stop:1 darkgray);
}

QMenuBar::item {
spacing:3px;/* spacing between menu bar items */
padding:1px4px;
background: transparent;
border-radius:4px;
}

QMenuBar::item:selected {/* when selected using mouse or keyboard */
background:#a8a8a8;
}

QMenuBar::item:pressed {
background:#888888;
}
少壮不识cpp,老大方知cpp可怕
原文地址:https://www.cnblogs.com/Jacket-K/p/7997435.html