【问题标题】:How to set background color to Row?如何将背景颜色设置为行?
【发布时间】:2019-02-28 08:53:07
【问题描述】:

我正在尝试为我的应用程序中的 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
                        }
                }


        }
}

它弄乱了图像:-

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

【问题讨论】:

    标签: qt background qml background-image background-color


    【解决方案1】:

    行放在矩形中

        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
                                }
                        }
    
                }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      相关资源
      最近更新 更多