一、Qt Widgets 问题交流
1.
二、Qt Quick 问题交流
1.布局嵌套时出现循环绑定提示
多个布局嵌套使用时,如果绑定了 parent 布局的宽高为 item 的 preferred 宽高,就会出现循环绑定的提示。可以把尺寸绑定到外层的组件消除该提示。
错误示例:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("龚建波 1992")
ColumnLayout{
anchors.fill: parent
Component.onCompleted: console.log("col")
RowLayout{
id: row
Layout.fillHeight: true
Layout.fillWidth: true
Component.onCompleted: console.log("row")
//嵌套使用布局时,绑定布局会出现循环绑定的提示
//此时需要有元素fillWidth才能正常显示
Rectangle{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: row.width*0.4
color: "green"
Component.onCompleted: console.log("green")
}
Rectangle{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: parent.width*0.6
color: "red"
Component.onCompleted: console.log("red")
}
}
//未嵌套布局时,无提示
Rectangle{
Layout.fillWidth: true
Layout.preferredHeight: parent.height*0.5
color: "orange"
Component.onCompleted: console.log("orange")
}
}
}
2.ListView 横项滚动条
ListView 的横项滚动条默认是有问题的,参照 QTBUG-82290
一种解决方式是设置两个属性:
contentWidth: 1200
flickableDirection: Flickable.HorizontalAndVerticalFlick
完整代码:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
width: 640
height: 480
visible: true
title: qsTr("龚建波 1992")
ListView{
anchors.fill: parent
anchors.margins: 10
model: 100
spacing: 10
clip: true
contentWidth: 1200
flickableDirection: Flickable.HorizontalAndVerticalFlick
boundsBehavior: Flickable.StopAtBounds
delegate: Rectangle{
width: 1200
height: 30
border.color: "red"
}
ScrollBar.vertical: ScrollBar{
policy: ScrollBar.AlwaysOn
}
ScrollBar.horizontal: ScrollBar{
policy: ScrollBar.AlwaysOn
}
}
}
三、其他
1.