• 4493阅读
  • 1回复

Qml MenuItem 改变文字颜色 [复制链接]

上一主题 下一主题
离线pppop3
 

只看楼主 倒序阅读 楼主  发表于: 2014-09-19

Menu {
        title: "文件(&F)"
        MenuItem {
        id:openMenu
           text:"打开"
           shortcut: "Ctrl+s"
        }
        MenuItem {
            text: "关闭"
            shortcut: "Ctrl+p"
        }
        MenuItem {
            text: "你好"
            shortcut: "Ctrl+,"
        }
}
请问怎么修改Menu 和MenuItem 的字体颜色,我尝试用style但是发现itemDelegate是只读的 或者说 我要自己定义一个itemDelegate ?最好有资料或者例子 谢谢给位
离线qyvlik

只看该作者 1楼 发表于: 2015-04-21
Menu{
    property int size: FlatGlobal.sizeDefault
    property ActiveColor type : FlatGlobal.typeDefault;

    // because the frame color is same as typeInverse.color;
    onTypeChanged:{
        if(type.objectName == FlatGlobal.typeInverse.objectName){
            type = Qt.binding(function(){
              return FlatGlobal.typeDefault;
            });
        }
    }

    style:MenuStyle {
        frame:Rectangle{
            color:FlatGlobal.typeInverse.inactiveColor;
            //radius: FlatGlobal.radius;
        }
        itemDelegate.background : Rectangle {
            color:FlatGlobal.typeInverse.inactiveColor;
            //radius: FlatGlobal.radius;
        }
        itemDelegate.label: Label {
            font.family: FlatGlobal.font.family;
            font.pointSize: size;
            text:styleData.text
            color:styleData.selected ? type.activeColor :type.inactiveColor
        }
    }
}
ubiboot
快速回复
限100 字节
 
上一个 下一个