首页 > 解决方案 > raspbian qt 虚拟键盘 黑顶屏

问题描述

我在 ubuntu 和 windows 10 中运行 Qt 虚拟键盘示例非常好,但在 raspbian 上它仅在全屏模式下运行,使用虚拟键盘键入时我看不到文本编辑。我希望虚拟键盘宽度适合窗口大小并显示在文本编辑下。如何 ?

import sys
import os
from PySide2.QtWidgets import *

os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"

app = QApplication([])
w = QWidget()
vl = QVBoxLayout(w)
btn = QPushButton()
btn.setText('Start')
vl.addWidget(btn)
tb = QLineEdit()
vl.addWidget(tb)

w.show()
sys.exit(app.exec_())

Windows 10 上的结果:

在此处输入图像描述

但在 raspbian 上它看起来像:

在此处输入图像描述

我该如何解决?请帮忙

标签: pythonqtraspbianqtvirtualkeyboard

解决方案


我有同样的问题。(QT 5.11.3)这看起来完全像这个错误:

建议的解决方法是将 QQuickWindow 的颜色设置为透明。例如

QQuickWindow *window = qobject_cast<QQuickWindow *>(YourRootQuickObj );

QSurfaceFormat surfaceFormat = window->requestedFormat();
surfaceFormat.setAlphaBufferSize(8);
surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);

window->setFormat(surfaceFormat);
window->setColor(QColor(Qt::transparent)); //Workaround
window->setClearBeforeRendering(true);

window->showFullScreen();

此问题似乎已在 QT 5.15 中修复。我目前正在构建这个版本,我会报告这个版本是否会修复这个错误。


推荐阅读