qml中使用Qt.fontFamilies()可以返回字体的列表, 我们用一个ListView显示出来
ListView{
id: comb
anchors.fill: parent
model: Qt.fontFamilies()
delegate: Item {
height: 32
width: parent.width
Rectangle{
id: fontSelect
height: 24
width: parent.width
Text {
id: txtShow
anchors.left: parent.left
anchors.leftMargin: 6
verticalAlignment: Text.AlignVCenter
text: qsTr("Select Font 选择字体")
font.family: modelData
font.pixelSize: 14
}
Text {
id: txtFont
anchors.left: txtShow.right
anchors.leftMargin: 6
anchors.verticalCenter: txtShow.verticalCenter
verticalAlignment: Text.AlignVCenter
text: modelData
font.pixelSize: 14
}
}
Rectangle {
height: 2
width: parent.width
anchors.top: fontSelect.bottom
color: "#148014"
}
MouseArea{
anchors.fill: parent
onClicked: {
emit: sClick(modelData);
fontList.visible = false;
}
}
}
}
show.gif
需要完整代码请访问QtQuickExamples
网友评论