qtquick2

Add objects to QML layout from C++

一世执手 提交于 2019-12-13 19:36:13
问题 How can I, from the C++, add some more Rectangle s dynamically to the one with id root ? For example, two more Rectangle s colored red and green ? main.qml: Rectangle { id: root } Typical QML objects to add under 'root': Rectangle { color: "red"; width: 200; height: 200 } Rectangle { color: "green"; width: 200; height: 200 } Qt Creator generated main.cpp : int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral

Calling qmlRegisterType() in the registered class on debug crashes application

我怕爱的太早我们不能终老 提交于 2019-12-13 16:27:13
问题 I want to use qmlRegiterType() in registered class itself. I tried to use method from this topic but whenever I try to run application in debug mode it crashes the application with error read access violation at 0x0 Crashes on macro QML_GETTYPENAMES inside qqml.h (235 line). TestClass.h : class RegisterQmlTest : public QObject { Q_OBJECT public: explicit RegisterQmlTest(QObject *parent = 0); }; TestClass.cpp : QML_REGISTER(RegisterQmlTest); RegisterQmlTest::RegisterQmlTest(QObject *parent) :

how to create components dynamically in qml

删除回忆录丶 提交于 2019-12-13 11:19:51
问题 How to dynamically add components in QML? I refered this link to add a component(Rectangle component) into main.qml window upon a button click in same window. 'Ubuntu.Components' is not installed in my qt. I don't know javascript. "componentCreation.js"is refered here. What does it means? i am beginner in qml . i need to know is there a way to load qml comonents dynamically by using qml only. 回答1: main.qml import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 Window { id

How to change position in a ColumnLayout

六眼飞鱼酱① 提交于 2019-12-13 06:49:21
问题 I am a newbie in QML and I made a "accordion" item. I modified a not complete QML project for that. For that, I use PanelItems : Item { default property var contentItem: null property string title: "panel" id: root Layout.fillWidth: true height: 30 Layout.fillHeight: current property bool current: false ColumnLayout { anchors.fill: parent spacing: 0 Rectangle { Drag.active: dragArea.drag.active id: bar Layout.fillWidth: true height: 30 color: root.current ? "#81BEF7" : "#CEECF5" Text {

Is QQuickFramebufferItem the C++ equivalent of QML's Canvas 3D?

北城余情 提交于 2019-12-13 06:39:35
问题 What I want is a way to create a Qt Quick item drawn using custom OpenGL code. I seem to have found 2 ways: Subclass QQuickFramebufferItem and write my OpenGL code in C++ Create a Canvas3D item in QML and draw to it from Javascript Do these two ways really have the same purpose, with the main difference that they're used from different languages? 来源: https://stackoverflow.com/questions/39596473/is-qquickframebufferitem-the-c-equivalent-of-qmls-canvas-3d

Easy way to configure QML combobox with 1-25

为君一笑 提交于 2019-12-13 03:45:35
问题 I have a need for a simple drop-down box containing the numbers 1 through 25 inclusive. If I set the model up as a simple 25 , I get the values 0 through 24 inclusive. I know I can have a more complicated list model but it seems rather silly to construct a massive array of values when they should be able to be calculated on the fly. From what I read, it should be a simple matter to create a delegate for setting the display values but, with the QML: ComboBox { width: 100 model: 25 delegate:

How to animate scroll in a QML ScrollView?

纵然是瞬间 提交于 2019-12-13 03:09:01
问题 How can I animate scrolling in a QML ScrollView? I've tried a Behavior on the contentItem.contentY , but that isn't working. 回答1: With Qt Quick Controls 1 You just have to animate the value changes on the property flickableItem.contentY . A quick example: Item { anchors.fill: parent ColumnLayout { anchors.fill: parent Button { id: btn onClicked: scroll.scrollTo(scroll.flickableItem.contentY + 100) } ScrollView { id: scroll function scrollTo(y) { scrollAnimation.to = y scrollAnimation.start()

How to scroll to certain row in QML TreeView

℡╲_俬逩灬. 提交于 2019-12-13 02:58:32
问题 In TreeView , selecting a row by clicking it. But I want to focus the row in TreeView by indicating the row QModelIndex and roleName . I found similar function in ListView : positionViewAtIndex(int index, PositionMode mode) How to do this in TreeView ? 回答1: Try to use hidden variable __listView. __listView.positionViewAtIndex(row, mode) 来源: https://stackoverflow.com/questions/46441998/how-to-scroll-to-certain-row-in-qml-treeview

QQuickView: handling mouse events in C++

不打扰是莪最后的温柔 提交于 2019-12-12 15:18:10
问题 I render my 3d model under qml controls using QQuickView::beforeRendering event. I want to do my mouse events handling in C++ if user clicks outside any of qml controls/ How can I found out in QQuickView::mousePressEvent that mouse is pressed outside qml controls? 回答1: I think it's easier to do it with a custom QQuickItem , because doing it with a custom QQuickView apparently means that you get the events before they reach any of the items. Here's an example: #include <QtQuick> class MyItem :

Difference in QML between Window and Item in parent-children relationship

醉酒当歌 提交于 2019-12-12 15:15:38
问题 I'm wondering why for Item this works: Item { id: root width: 640 height: 480 MouseArea { anchors.fill: (root or parent. It doesn't matter) onClicked: console.log("clicked") } } But for Window it doesn't. Only anchoring by parent will work, but for anchoring by id it will fail. 回答1: According to the documentation, anchors.fill requires the argument either to be or to identify an Item -derived object. From here you can follow the inheritance chain of Window and see that it is not actually an