您的位置:首页 > 其它

qml中Control组件以及Style组件解析

2018-03-20 15:49 141 查看
在实际的开发过程中避免不了需要自己进行相关控件的开发.
今天就简单介绍一下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官方提供的组件基本上就是通过这两个组件而来.  
大家多看几遍基本上就都了解了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐