qml自定义界面定制(二)从左到右,icon加文本按钮

扶醉桌前 提交于 2020-01-24 22:38:53
/*
  从左到右,icon +文字的按钮
*/
import QtQuick 2.0

 
Rectangle {
    height: 50;
    width: parent.width
    signal iconClicked();
    signal iconEntered();
    signal iconExited();
    property alias iconSrc: icon.source
    property alias iconText: iconLabel.text
    Image {
        id: icon
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.verticalCenter: parent.verticalCenter
    }
    Text {
        id: iconLabel
        color: "#3B3E50"
        font.pixelSize: 16
        elide: Text.ElideRight
        width: parent.width-icon.width +60
        anchors.left: icon.right
        anchors.leftMargin: 10
        anchors.verticalCenter: parent.verticalCenter
    }

 
    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.LeftButton
        onClicked:{
            iconClicked();
        }
        onEntered: {
            iconLabel.color = "#4E84F3"
            iconEntered();
        }
        onExited: {
            iconLabel.color = "#3B3E50";
            iconExited();
        }
    }
}

 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!