【问题标题】:Text control not showing in QT ApplicationWindowQT ApplicationWindow 中未显示文本控件
【发布时间】:2020-05-04 06:11:18
【问题描述】:

我已经安装了 Qt 5.12.0 并创建了 QtQuick 空应用程序。我在main.qml下面添加了代码

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.4

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Text {    
        text: "Qt Quick"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        font.pointSize: 24; font.bold: true
    }
}

运行应用程序时文本控件不显示

【问题讨论】:

  • 代码正确,可以正常工作
  • 还有什么其他原因,比如不正确的配置或设置?
  • 我按照你的帖子运行它
  • 尝试改变文本的颜色,看看它是否隐藏在窗口的背景颜色上。这可能是由您平台上的主题问题引起的。

标签: qt qml


【解决方案1】:

确保根据https://doc.qt.io/qt-5/qtquick-deployment.html 设置您的 .pro 文件和 main.cpp

应用程序的 .pro 项目文件必须为 QT 变量指定声明性模块。例如:

TEMPLATE += app
QT += quick
SOURCES += main.cpp

只是一个旁注;您使用的框架称为 Qt,而不是 QT。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-06
    • 2017-06-22
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    相关资源
    最近更新 更多