我正在尝试使用 QtQuickControls2 对话框:
Dialog {
id: dialog
x: parent.width/2-width/2
y: parent.height/2-height/2
width:300
height:200
title: "Warning"
modal: true
standardButtons: Dialog.Ok
visible: false
onAccepted: console.log("Ok clicked")
}
Button {
id: button
objectName: "doSomethingButton"
onClicked: {
if(problemFlag==true)
dialog.visible=true
}
}
Run Code Online (Sandbox Code Playgroud)
如果按钮被点击并且problemFlag是 ,它应该被触发true。我读到如果modal设置为true用户无法与程序的其余部分交互。但是,如果我单击对话框外的某处,它就会消失(无需单击“确定”)。
I have a c++ project with several subdirectories, e.g.
src/
CMakeLists.txt
main.cpp
module1/
CMakeLists.txt
code.cpp
code.h
module2/
CMakeLists.txt
code2.cpp
Run Code Online (Sandbox Code Playgroud)
It seems that the two ways to deal with this in cmake is to either use add_subdirectory(module1) or include(module1) in my src/CMakeLists.txt. Somewhere I read, that the include use is regarded legacy/deprecated. My src/module1/CMakeLists.txt looks like this:
include_directories(${CMAKE_CURRENT_LIST_DIR})
set( SRCS
${SRCS}
${CMAKE_CURRENT_LIST_DIR}/code.cpp
)
set( QT_FILE_HEADERS
${QT_FILE_HEADERS} code.h
)
Run Code Online (Sandbox Code Playgroud)
If I try to use the add_subdirectory method and want to use …
我想ListView在 QML 中将我的 C++ 类显示为 a。我有一个空向量,稍后将被填充:
QList<QObject*> _myList;
Run Code Online (Sandbox Code Playgroud)
并设置上下文
QQmlContext *ctxt = _eng->rootContext();
ctxt->setContextProperty("modelName",QVariant::fromValue(_myList));
Run Code Online (Sandbox Code Playgroud)
在 qml 文件中我有
ListView {
id: listView
model: modelName
delegate: myDelegate {}
}
Run Code Online (Sandbox Code Playgroud)
但是启动应用程序时出现以下错误
qrc:/screen2.qml:252: ReferenceError: modelName is not defined
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?奇怪的是,该错误并不会阻止列表在填满后正确显示。
我在C ++中有一个QQuickItem,它在QML应用程序中实例化。如果我的QQuickItem的width属性改变,我想在c ++端触发一个自定义函数。
在QML中,我将执行onWidthChanged:{我的代码}。我该如何在c ++方面做到这一点?
我想为a 中的ToolTip代表做一个. 如果我使用 an ,它工作得很好,但是,我不能使用 an,因为它破坏了 的选择模式。如果我尝试在我的委托组件中定义,我会收到错误ComponentTableViewItemDelegateItemDelegateTableViewToolTip
qrc:/FileSystem.qml:34 Invalid component body specification
Run Code Online (Sandbox Code Playgroud)
如何使用工具提示Component?
这是我的代码:
TreeView {
id: view
anchors.fill: parent
sortIndicatorVisible: true
model: fileSystemModel
rootIndex: rootPathIndex
selection: sel
selectionMode: 2
Component {
id: mycomp
Row{
id: myrow
CheckBox{
id: cbox
anchors.baseline: ctext.baseline
}
Text{
id: ctext
text: styleData.value
color: styleData.textColor
width: namecolumn.width-cbox.width-myrow.x
elide: Text.ElideRight
}
}
NC.ToolTip {
parent: mycomp
visible: hovered
delay: 1000
text: qsTr(styleData.value)
}
}
TableViewColumn { …Run Code Online (Sandbox Code Playgroud) 我有几个qml文件,每个文件都在我的应用程序中定义一个屏幕.有时,一个屏幕上的操作应该更改不同屏幕上的项目.现在我通过设置属性Item buttonId然后执行此操作
for (var i = 0; i < buttonId.parent.children.length; i++) {
buttonId.parent.children[i].state="inactive"
}
Run Code Online (Sandbox Code Playgroud)
是否可以直接访问不同文件中的项目/对象,例如通过他们的ID?
我正在用QML创建一个绘图组件.我的QML组件的结构如下所示:
Rectangle {
id: canvas
objectName: "myPlot"
Rectangle {
id: plot
PlotArea {
id: pa
} // this is my c++ QQuickItem
MouseArea {} // for handling interaction with the plot, like zooming
XAxis{}
YAXis{}
}
}
Run Code Online (Sandbox Code Playgroud)
这PlotArea是我的c ++课程.我需要从C++与这个QML组件进行交互,更准确地说,我需要调用一个成员函数PlotArea来向绘图中添加数据.通常的方法是使用findChild<QObject*>("objectName"),但由于组件将被重用,我不能给PlotArea和对象名称.
PlotArea如果我有指针,我该如何访问"myPlot"?我试过了
QObject *plot = rootObjects.value(0)->findChild<QObject*>("plotObject");
PlotArea * myplot = (plot->findChild<PlotArea*>("pa"));
Run Code Online (Sandbox Code Playgroud)
但这不起作用.但是,如果我这样做,那么上述方法是有效的
PlotArea {
id: pa
objectName: "pa"
} // this is my c++ QQuickItem
Run Code Online (Sandbox Code Playgroud)
但是我想知道这是否安全,因为在我的应用程序中会有服务PlotAreas,并且所有这些都有"pa"这个名字.