首页 > 解决方案 > 如何将背景颜色设置为行?

问题描述

我正在尝试为我的应用程序中的 Row 元素提供背景颜色。到目前为止,我用矩形存档了这个,但它弄乱了 MouseArea 中的图像

这是我的代码:-

import QtQuick.Controls  2.4
import QtQuick 2.11

ApplicationWindow {

        id:rootAppWin
        width:640
        height:480
        visible: true

        StackView {

                id: rooAppStack
                anchors.bottomMargin: 50
                anchors{
                        fill:parent
                }
        }

        //Bottom Buttons
        Row{

                Rectangle {
                        color: "#19d4d4d4"
                        anchors.fill:parent
                }

                id:rootNavButtons
                anchors{
                        top: rooAppStack.bottom
                        right: parent.right
                        bottom: parent.bottom
                        left: parent.left
                        topMargin: 5
                }

                MouseArea {
                        id:marootback
                        width: parent.width/2
                        height: parent.height
                        Image {
                                id: marootbackimg
                                fillMode: Image.PreserveAspectFit
                                source: "qrc:/img/sideswipe.svg"
                                anchors.fill:parent
                        }
                }

                MouseArea {
                        id:maroothome
                        width: parent.width/2
                        height: parent.height
                        Image {
                                id: maroothomeimg
                                fillMode: Image.PreserveAspectFit
                                source: "qrc:/img/tent.svg"
                                anchors.fill:parent
                        }
                }


        }
}

它弄乱了图像:-

在此处输入图像描述

没有矩形它很好用,但我不能设置背景颜色。我应该怎么办 ?

标签: qtbackgroundqmlbackground-imagebackground-color

解决方案


行放在矩形中

    Rectangle {
            color: "#19d4d4d4"
            anchors{
                    top: rooAppStack.bottom
                    right: parent.right
                    bottom: parent.bottom
                    left: parent.left
                    topMargin: 5
            }
            Row{
                    anchors.fill:parent
                    id:rootNavButtons
                    MouseArea {
                            id:marootback
                            width: parent.width/2
                            height: parent.height
                            Image {
                                    id: marootbackimg
                                    fillMode: Image.PreserveAspectFit
                                    source: "qrc:/img/sideswipe.svg"
                                    anchors.fill:parent
                            }
                    }

                    MouseArea {
                            id:maroothome
                            width: parent.width/2
                            height: parent.height
                            Image {
                                    id: maroothomeimg
                                    fillMode: Image.PreserveAspectFit
                                    source: "qrc:/img/tent.svg"
                                    anchors.fill:parent
                            }
                    }

            }

    }

推荐阅读