qml中Control组件以及Style组件解析
2018-03-20 15:49
141 查看
在实际的开发过程中避免不了需要自己进行相关控件的开发.
今天就简单介绍一下Control以及Style组件的用法
首先我们可以看下Control.qml的代码:
/****************************************************************************
下面的是Style.qml的代码:
/****************************************************************************
我们开发自己的组件,一般情况下通过集成Control还有Style基本上就可以满足我们的要求. 因为Qt Qml官方提供的组件基本上就是通过这两个组件而来.
大家多看几遍基本上就都了解了.
今天就简单介绍一下Control以及Style组件的用法
首先我们可以看下Control.qml的代码:
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.2
import QtQuick.Controls.Styles 1.1
/*!
\qmltype Control
\internal
\qmlabstract
\inqmlmodule QtQuick.Controls.Private
*/
FocusScope {
id: root
/*! \qmlproperty Component Control::style
The style Component for this control.
\sa {Qt Quick Controls Styles QML Types}
*/
property Component style
/*! \internal */
property QtObject __style: styleLoader.item
/*! \internal */
property Item __panel: panelLoader.item
/*! \internal */
property var styleHints
implicitWidth: __panel ? __panel.implicitWidth: 0
implicitHeight: __panel ? __panel.implicitHeight: 0
baselineOffset: __panel ? __panel.baselineOffset: 0
activeFocusOnTab: false
/*! \internal */
property alias __styleData: styleLoader.styleData
Loader {
id: styleLoader
sourceComponent: style
property Item __control: root
property QtObject styleData: null
onStatusChanged: {
if (status === Loader.Error)
console.error("Failed to load Style for", root)
}
}
Loader {
id: panelLoader
anchors.fill: parent
sourceComponent: __style ? __style.panel : null
onStatusChanged: if (status === Loader.Error) console.error("Failed to load Style for", root)
}
}感觉没有什么好讲的,无非就是声明了几个变量,使用了Loader组件加载了Style. 还有一个loader组件加载了Style.qml中的panel组件.并且以anchors.fill的方式进行布局.个人感觉Qt官方在设计的时候应该是考虑将一个控件的控制逻辑个界面设计完全隔离开来而进行的设计,没什么好说的/
下面的是Style.qml的代码:
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Private 1.0
/*!
\qmltype Style
\internal
\inqmlmodule QtQuick.Controls.Private
*/
AbstractStyle {
/*! The control this style is attached to. */
readonly property Item control: __control
}这个更简单,就是声明了一个control变量, 这个变量是用来做什么的呢? 这个control就是控制一个组件对象,也就是前面的Control.qml组件.
我们开发自己的组件,一般情况下通过集成Control还有Style基本上就可以满足我们的要求. 因为Qt Qml官方提供的组件基本上就是通过这两个组件而来.
大家多看几遍基本上就都了解了.
相关文章推荐
- Windows Server 2012 R2安装IIS,ftp等组件,绑定服务器域名,域名解析到服务器,域名备案,以及安装期间错误的解决方案
- 阿里云学生优惠Windows Server 2012 R2安装IIS,ftp等组件,绑定服务器域名,域名解析到服务器,域名备案,以及安装期间错误的解决方案
- 自学Android历程->Android项目基本目录解析以及基本的组件
- Creating a Pager Control for ASP.NET以及Dino Esposito 分页组件的一个 Bug
- header头信息解析以及CORS 跨域 access-control-allow-headers 的问题
- STL 格式解析--文本以及二进制格式
- 嵌入式 对字符串中特定字符计数以及据特定字符解析字符串
- MySql Join理论以及SQL的解析步骤
- XML - 十分钟了解XML结构以及DOM和SAX解析方式
- 仿知乎程序(三)读取webService,解析json,volley以及PullToRefreshListView的使用
- 各种组件使用以及详解和各种小demo地址集
- 随便聊聊 SOA & SOAP & WebService 的一些东西,以及客户端开发的代码逻辑解析
- 卡特尔16中人格分析,测试题,答案,以及解析
- 张正友相机标定Opencv实现以及标定流程&&标定结果评价&&图像矫正流程解析(附标定程序和棋盘图)
- 解析Qt自带的Style示例
- JSON解析的内容中含有table标签怎么处理以及自定义标签的处理
- vue分页组件table-pagebar使用实例解析
- EventBus3.0以及老版本源码解析
- 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解析
- for_each,count,mismatch等STL算法在VS2013下的实现以及辅助函数的源码解析