首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >修复项目组件中图像的大小

修复项目组件中图像的大小
EN

Stack Overflow用户
提问于 2019-04-04 23:00:11
回答 1查看 31关注 0票数 0

我想在一个项目中固定图像的大小,并在它的右边有一个更高的矩形。

下面是我的组件的声明

代码语言:javascript
运行
复制
import QtQuick 2.9
import QtQuick.Controls 2.5

Item {
    id: button
    width: 100
    height: 200
    signal clicked

    Image {
        id: backgroundImage
        anchors.fill: parent
        source: (button.enabled ? "images/simulation.png" : "images/simulation.png")
        width: 100
        height: 100
    }

    Rectangle {
        color: "#22add8"
        anchors.left: backgroundImage.right
        anchors.leftMargin: 10
        width: 5
        height: 200
    }

    //Mouse area to react on click events
    MouseArea {
        anchors.fill: button
        onClicked: {
            console.log("clicked")
            button.clicked()
        }
        onPressed: {
            console.log("pressed")
            backgroundImage.source = "images/simulation.png" }
        onReleased: {
            console.log("released")
            backgroundImage.source = (button.enabled ? "images/simulation.png" : "images/simulation.png")
        }
    }
}

图像始终采用项目的高度

如何确定图片的大小?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-05 01:50:17

这就是罪魁祸首:

代码语言:javascript
运行
复制
Image {
    // ...
    anchors.fill: parent    //  <-- THIS
    // ...
}

这将绑定图像的区域以填充其父图像。去掉这一行,你应该得到一个100x100的固定图像。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55519178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档