QML中利用ColumnLayout 、Rectangle、Grid布局方法:
anchors.fill:parent:锚点布局:填充父窗口
Layout.fillHeight:true 填充高度
Layout.fillWidth:true 填充宽度
布局思路:先用ColumnLayout,然后再用Rectangle划分每个区域,在rectangle中再RowLayout或Grid
进行布局,如果一行的控件比较多建议使用Grid,这里注意一行中的对齐方式的设置,如果想所一行中的所有控件都竖向居中,首先在上一级布局控件中设置竖向居中,然后在本级控件中设置竖向居中,个人一点学习新得,如有不妥欢迎批正!共同学习!
Dialog {
id:dmdialog
width: 959
height: 675
title: "周视图"
visible: false
ColumnLayout{
anchors.fill: parent
Rectangle{
Layout.fillHeight: true
Layout.fillWidth: true
TableView {
id:tbv
anchors.fill: parent
model: dataModel
sortIndicatorVisible:true
TableViewColumn {
role: "Id";title: "查询项";width: 100}
TableViewColumn {
role: "cameraName"; title: "周一";width: 100}
TableViewColumn {
role: "checkPointName"; title: "周二"; width: 100}
TableViewColumn {
role: "channelId"; title: "周三";width: 100}
TableViewColumn {
role: "containStraight"; title: "周四"; width: 100}
TableViewColumn {
role: "containLeft"; title: "周五";width: 100}
TableViewColumn {
role: "containRight"; title: "周六"; width: 100}
TableViewColumn {
role: "countTime"; title: "周日";width: 150}
headerDelegate: Rectangle{
implicitWidth: 10
implicitHeight: 24
border.color: "white"
color: "gray"
border.width: 1
MouseArea
{
id: mous
anchors.fill: parent
//接收左键和右键
acceptedButtons:Qt.LeftButton | Qt.RightButton;
Text{
id:headertext
anchors.fill: parent
text: styleData.value
color: styleData.pressed ?"blue" : "white"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pointSize: 11
font.bold: true
}
onClicked: {
if (mouse.button === Qt.RightButton)
{
//发射自定义信号
var colId=0;
if(headertext.text=="编号")
{
colId=0;
}

最低0.47元/天 解锁文章
1078

被折叠的 条评论
为什么被折叠?



