自己重新定义的一个窗口控件
2018-03-28 16:27
316 查看
在使用QML进行开发的时候,经常会遇到需要自己进行定义控件的情况,
举个例子,譬如说我们在使用ApplicationWindow的时候会遇到系统自带的一些最大化,最小化按钮值类的情况.这些默认的情况,但是这些可能并不适合每一个人. 因为不同的开发者都有自己不同的喜好.
今天我zaiApplicationWindow控件的基础上重新封装了一个适合 自己的控件.
好吧,我们先直接上源码,之后再简单介绍下这个控件的使用方法
AbstractWindow.qml:
import QtQuick 2.9
使用方法:
AbstractWindow{
运行情况:
其实也是很简单的情况,就是将整个主界面分成上中下三个区域. 每个区域都是一个组件.这个应该属于个人定制. 不同的开发者可以根据自己的需求进行修改
举个例子,譬如说我们在使用ApplicationWindow的时候会遇到系统自带的一些最大化,最小化按钮值类的情况.这些默认的情况,但是这些可能并不适合每一个人. 因为不同的开发者都有自己不同的喜好.
今天我zaiApplicationWindow控件的基础上重新封装了一个适合 自己的控件.
好吧,我们先直接上源码,之后再简单介绍下这个控件的使用方法
AbstractWindow.qml:
import QtQuick 2.9
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
ApplicationWindow{
id:abstractWindow
visible: true
width: 985
height: 680
minimumWidth: 100
minimumHeight: 60
signal clicked()
flags: Qt.FramelessWindowHint | Qt.WindowSystemMenuHint| Qt.WindowMinimizeButtonHint| Qt.Window
property color absWindowColor: "#0000cc"
property real absToolBarHeight: 50
property real absFootBarHeight: 80
readonly property int close:-1
readonly property int showMinmized : 1
readonly property int e194 showNormal : 2
readonly property int showMaxmized : 3
readonly property int showFullScreen : 4
property int showState: 0
onShowStateChanged: {
if(showState === 0){
var e;
try{
abstractWindow.close();
// window.destroy(10);
}catch(e){
console.debug(abstractWindow,"destroy has some error",e);
}
}
}
onWindowStateChanged: {
switch(windowState)
{
case 0x00000000:
showState = 0;
break;
case 0x00000001:
showState = showMinmized;
break;
case 0x00000002:
showState = showMaxmized;
break;
case 0x00000004:
showState = showFullScreen;
}
}
property Component absContent
property alias absContectControl: __absContentLoader.item
Loader{
id:__absContentLoader
anchors.fill: parent
sourceComponent: absContent ? absContent : null
}
style: ApplicationWindowStyle{
background: Rectangle{
color: abstractWindow.color
border.width: 1
border.color:absWindowColor
}
}
property alias absToolControl: __absToolLoader.item
property Component absToolBar
toolBar: Rectangle{
id:absTitleBar
width: parent.width
height: absToolBarHeight
MouseArea {
// 鼠标拖拽窗口移动
id:__absTitlebarArea;
anchors.fill: parent
property point previousPosition
onPressed: previousPosition = Qt.point(mouseX, mouseY);
onPositionChanged: {
if (pressedButtons == Qt.LeftButton) {
var dx = mouseX - previousPosition.x;
var dy = mouseY - previousPosition.y;
abstractWindow.x = abstractWindow.x + dx;
abstractWindow.y = abstractWindow.y + dy;
}
}
}
Loader{
id:__absToolLoader
anchors.fill: parent
sourceComponent: absToolBar ? absToolBar : null
}
}
property alias absFooterControl: __absFootBarLoader.item
property Component absFootBar
statusBar: Rectangle{
id:absStatusBar
width: parent.width
height: absFootBarHeight
Loader{
id : __absFootBarLoader
anchors.fill : parent
sourceComponent : absFootBar ? absFootBar : null
}
}
}
使用方法:
AbstractWindow{
id:root
absToolBar:Rectangle{
color: "red"
IconButton{
anchors.right: parent.right
anchors.rightMargin: 15
anchors.top:parent.top
anchors.topMargin: 15
iconImage: Resource.close
onClicked: {
Qt.quit()
}
}
}
absContent:Rectangle{
color: "gray"
}
absFootBar:Rectangle{
color: "lightblue"
}
}
运行情况:
其实也是很简单的情况,就是将整个主界面分成上中下三个区域. 每个区域都是一个组件.这个应该属于个人定制. 不同的开发者可以根据自己的需求进行修改
相关文章推荐
- 让自己写的子窗口可以被父对话框的TAB键切换,像一个控件一样
- WTL 通过IWebBrowser2接口使WebBrowser控件在自己的窗口打开网页
- 自学QT之自己写一个窗口
- ABAP 自己定义一个长文本TEXT的编写、保存
- MVC分页控件之二,为IQueryable定义一个扩展方法,直接反回PagedList<T>结果集(转)
- 一个树控件类的实现---打造自己的树控件
- 同一个窗口中不同的按钮控件使用同一个storyboard的方法(WPF)
- Android自己定义控件——3D画廊和图像矩阵
- Android自己定义控件--圆形进度条(中间有图diao)
- 终于学会了自己定义一个文件扩展名,可以通过iis识别执行的
- 写一个自己定义进度颜色和圆形转动的ProgressBar(具体介绍)
- String、StringBuffer和StringBuilder,定义一个自己的StringBuilder的类
- 手把手带你画一个 时尚仪表盘 Android 自己定义View
- Android 让他们自己控制开发的定义(一个)
- 面试题:一个短小强悍的C++面试题---违背Effective C++的条款37:绝不重新定义继承而来的缺省参数值
- 抛出异常及声明异常 自己定义一个异常
- 由于一个或多个其它网络页属性已经打开,这个属性页上的部分控件被禁用,要想使用这些软件,请先关闭所有属性页,然后将这个属性页重新打开
- C#自己写的一个自定义分页控件
- 自己定义一个outputFormat