【发布时间】:2014-12-09 11:43:51
【问题描述】:
我在尝试按照documention 设置按钮背景时遇到了很多困难。
由于某种原因,Qt 找不到导入 QtQuick.Controls.Styles。我尝试以多种方式导入它,但没有成功。我的最后一次尝试:
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtGraphicalEffects 1.0
Button {
id: btn
property int row
property int col
property Item buttonPreview
property bool hasPreview: true
GridLayout.row: row
GridLayout.col: col
GridLayout.colSpan: 2
GridLayout.rowSpan: 2
width: 50
height: 50
style: ButtonStyle {
background: Rectangle {
color:"white"
}
}
...
}
我遇到以下错误:
-
import QtQuick.Controls.Styles 1.2代码下划线表示QML module not found -
Btn.qml:21:5: Cannot assign to non-existent property "style"在我使用应用程序时出现。
奇怪的是,如果我删除 import QtQuick.Controls.Styles 1.2,style: ButtonStyle { 会变成下划线。
我使用Qt 5.3.2。
我的 .pro 配置文件的一部分:
QT += core gui svg xml network quick gui-private qml quickwidgets widgets concurrent
TARGET = ProjectName
TEMPLATE = app
CONFIG += c++12 plugin
感谢您的任何想法,非常感谢您花时间帮助解决我的问题。
【问题讨论】:
-
您使用的是哪个 Qt 版本?
<qtdir>/qml/QtQuick/Controls/Styles中有什么内容? -
qml\QtQuick\Controls\Styles下有 2 个目录和一个文件:Base、Desktop 目录和 qmldir 文件。 -
顺便说一句,我认为
CONFIG += c++12必须是CONFIG += c++11。 -
好点应该是 c++11。我的 Qt creator 版本是 3.1。
-
你解决问题了吗。我也有同样的问题,我无法设置背景
标签: qt qml qt5 qt-quick qtquick2