一、Qt Widgets 问题交流
1.QOpenGLWidget的默认帧缓冲
参考文档:https://doc.qt.io/qt-5/qopenglwidget.html
QOpenGLWidget 渲染都发生在 OpenGL 帧缓冲对象中,makeCurrent() 绑定上下文。不能绑定到 ID 为 0 的帧缓冲对象作为默认缓冲,而应该调用 defaultFramebufferObject() 来获取 Qt 指定的缓冲对象 ID,该对象属于 context() 返回的上下文。通过 setParent 设置部件父级,或者调整窗口大小时,上下文和帧缓冲对象都会发生变化。
二、Qt Quick 问题交流 1.Qt5 中可见的组件过多时,弹出弹框会导致渲染异常(经测试,在 Qt6 中未复现)
不管是用 View 还是 Repeater 创建多个(我这里是 500 就会异常)Control 组件后,弹一个 Popup 弹框,此时渲染会有问题,要么弹框没正常显示,要么那些 Control 组件不可见了,再次点击或者拖动窗口使之刷新又恢复了原来的样式。
如下图,左侧是初始化界面,1000 个按钮,右侧是弹出弹框但渲染已经异常。
目前临时的解决办法是给每个 Control 组件设置 opacity: 0.99999,或者设置 layer.enabled: true,加上两者中的一个设置后就能正常渲染了,有人说是渲染批次问题。完整测试代码:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello Qt Bug")
color: "orange"
Popup {
id: pop
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
modal: true
width: 200
height: 200
padding: 0
background: Rectangle{
color: "yellow"
}
}
//可以用其他的view或者flow+repeater,只要能显示大量组件就行
GridView {
id: view
anchors.fill: parent
model: 1000
cellHeight: 11
cellWidth: 21
delegate: Button {
width: 20
height: 10
text: index
//opacity: 0.99999
//layer.enabled: true
}
}
Button {
anchors{
right: parent.right
bottom: parent.bottom
}
text: "pop"
onClicked: {
//pop.visible = true
pop.open()
}
}
}
2.Canvas font family 带空格时,需要用引号括起来
var ctx = getContext("2d");
ctx.font = "20px Microsoft YaHei";
如上代码在运行时会报错:
需要用引号将字体名称括起来:
ctx.font = "20px 'Microsoft YaHei'";
三、其他