当前位置:网站首页>Roson的Qt之旅#106 QML在图片上方放置按钮并实现点击按钮切换图片
Roson的Qt之旅#106 QML在图片上方放置按钮并实现点击按钮切换图片
2022-08-03 06:41:00 【Allen Roson】
QML完整代码如下:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQml.Models 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Image {
id: myImg1
width: parent.width
height: parent.height
source: "resouces/VN1.jpeg"
}
Image {
id: myImg2
width: parent.width
height: parent.height
source: "resouces/VN2.jpeg"
visible: false
}
Image {
id: myImg3
width: parent.width
height: parent.height
source: "resouces/VN3.jpeg"
visible: false
}
Button{
id: myBtn1
text: qsTr("皮肤1")
width: 50
height: 20
x: myImg1.width/2 - 95
y: myImg1.y + myImg1.height - 40
onClicked: {
myImg1.visible = true;
myImg2.visible = false;
myImg3.visible = false;
}
}
Button{
id: myBtn2
text: qsTr("皮肤2")
width: 50
height: 20
x: myImg1.width/2 - 25
y: myImg1.y + myImg1.height - 40
onClicked: {
myImg1.visible = false;
myImg2.visible = true;
myImg3.visible = false;
}
}
Button{
id: myBtn3;
text: qsTr("皮肤3")
width: 50
height: 20
x: myImg1.width/2 + 45
y: myImg1.y + myImg1.height - 40
onClicked: {
myImg1.visible = false;
myImg2.visible = false;
myImg3.visible = true;
}
}
}
运行效果如下:
记得要先将图片添加到资源文件中:
边栏推荐
猜你喜欢
随机推荐
【playwright】pytest-playwright增加代理服务选项
jvm 面试题
关于NOI 2022的报到通知
torch.nn.modules.activation.ReLU is not a Module subclass
STL - string
How to choose a reliable and formal training institution for the exam in September?
帆软11版本参数联动为null查询全部
【Shell】3万字图文讲解带你快速掌握shell脚本编程
解决登录vCenter提示“当前网站安全证书不受信任“
tmp
Detailed explanation and reproduction of AlexNet network
postman将接口返回结果生成json文件到本地
【云原生--Kubernetes】Pod重启策略
924. 尽量减少恶意软件的传播 前缀和
El - tree set using setCheckedNodessetCheckedKeys default check nodes, and a new check through setChecked specified node
数据库表结构文档 生成工具screw的使用
Week5
SSM整合流程
信息学奥赛一本通T1451:棋盘游戏
[机缘参悟-59]:《素书》-6-安于礼仪[安礼章第六]