qml mvc

这篇博客深入讨论了如何在Qt的QML中应用Model-View-Controller(MVC)设计模式,阐述了QML如何巧妙地结合 MVC 结构以实现高效且灵活的用户界面开发。
摘要由CSDN通过智能技术生成

撒發射點發生下功夫大師法國德國感


import QtQuick 2.15
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 1.4 as QtQuickCtrl1_4

Component {
    TableViewStyle {
            scrollBarBackground: Rectangle {
                color: "#F1F1F1"
                height: 17
                width: 17
            }

            corner : Component {
                Rectangle {
                    width: 17
                    height: 17
                    color: "#F1F1F1"
                }
            }

            decrementControl : Component {
                Rectangle {
                    id: control
                    x: 0
                    y: 0
                    width: 17
                    height: 17

                    property var hovered: styleData.hovered
                    property var pressed: styleData.pressed
                    color: control.pressed ? "#787878" : control.hovered ?
                                             "#D2D2D2" : "#F1F1F1"
                    Canvas {
                             id: canvas
                             anchors.centerIn: parent
                             width: 12
                             height: 8
                             contextType: "2d"

                             Connections {
                                 target: control
                                 function onPressedChanged() { canvas.requestPaint() }
                             }

                             function drawHorizontalIndicator() {
                                 canvas.height = 12
                                 canvas.width = 8
                                 context.reset()
                                 context.moveTo(0, height / 2)
                                 context.lineTo(width, 0)
                                 context.lineTo(width, height)
                                 context.closePath()
                                 context.fillStyle = control.pressed ? "#FFFFFF" : "#505050"
                                 context.fill()
                             }

                             function drawVerticalIndicator() {
                                 canvas.height = 8
                                 canvas.width = 12
                                 context.reset()
                                 context.moveTo(width / 2, 0)
                                 context.lineTo(0, height)
                                 context.lineTo(width, height)
                                 context.closePath()
                                 context.fillStyle = control.pressed ? "#FFFFFF" : "#505050"
                                 context.fill()
                             }

                             onPaint: {
                                 styleData.horizontal ? drawHorizontalIndicator() : drawVerticalIndicator()

                             }
                         }
                }

            }

            incrementControl : Component {

                Rectangle {
                    id: control
                    x: 0
                    y: 0
                    width: 17
                    height: 17

                    property var hovered: styleData.hovered
                    property var pressed: styleData.pressed
                    color: control.pressed ? "#787878" : control.hovered ?
                                             "#D2D2D2" : "#F1F1F1"
                    Canvas {
                             id: canvas
                             anchors.centerIn: parent
                             width: 12
                             height: 8
                             contextType: "2d"

                             Connections {
                                 target: control
                                 function onPressedChanged() { canvas.requestPaint() }
                             }

                             function drawHorizontalIndicator() {
                                 canvas.height = 12
                                 canvas.width = 8
                                 context.reset()
                                 context.moveTo(0, 0)
                                 context.lineTo(0, height)
                                 context.lineTo(width, height / 2)
                                 context.closePath()
                                 context.fillStyle = control.pressed ? "#FFFFFF" : "#505050"
                                 context.fill()
                             }

                             function drawVerticalIndicator() {
                                 canvas.height = 8
                                 canvas.width = 12
                                 context.reset()
                                 context.moveTo(0, 0)
                                 context.lineTo(width, 0)
                                 context.lineTo(width / 2, height)
                                 context.closePath()
                                 context.fillStyle = control.pressed ? "#FFFFFF" : "#505050"
                                 context.fill()
                             }

                             onPaint: {
                                 styleData.horizontal ? drawHorizontalIndicator() : drawVerticalIndicator()
                             }
                         }
                }

            }

            handle: Rectangle {
                color: "transparent"
                implicitHeight: 17
                implicitWidth: 17
                anchors.centerIn: parent
                QtQuickCtrl1_4.Button {
                    id: button
                    implicitHeight: parent.height - 4
                    implicitWidth: parent.width - 4
                    property var hovered: styleData.hovered
                    property var pressed: styleData.pressed
                    anchors.centerIn: parent
                    style: ButtonStyle {
                        background: Rectangle {
                            color: button.pressed ? "#787878" : button.hovered ?
                                                    "#A9A9A9" : "#C1C1C1"
                        }
                    }
                }
            }
        }
}




到翻跟斗雙方的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值