Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k Topics 77.6k Posts
  • Header not found in <appName>_qmltyperegistrations.cpp

    Solved qml c++ listview cmakelists.txt cmake
    3
    1 Votes
    3 Posts
    838 Views
    F
    @jsulm thanks! I just added target_include_directories(<appName> PUBLIC src) what works well.
  • Customizing QQuickWindow Rendering Operation

    Unsolved
    1
    0 Votes
    1 Posts
    181 Views
    No one has replied
  • StackLayout children have unpredictable widths

    Solved
    4
    0 Votes
    4 Posts
    437 Views
    mzimmersM
    @GrecKo said in StackLayout children have unpredictable widths: Is the with of equipmentPane always wrong or only in inCompleted? I'm not sure...the behavior now seems to be somewhat unpredictable. @GrecKo said in StackLayout children have unpredictable widths: The StackLayout might take a couple of frames to settle on its children size. Ah. So, what does one do to obviate this?
  • Dynamic SplitView

    Unsolved
    2
    1 Votes
    2 Posts
    936 Views
    V
    I had the same problem. My solution is to create two new items each time. Whenever you call the splitter function parent SplitView will get two children and so it will split into two. Be careful SamplePanel.qml should be SplitView. SamplePanel.qml import QtQuick 2.15 import QtQuick.Controls 2.15 SplitView { id: content Rectangle { id: mainContent anchors.fill: parent color: elementsColor Text { anchors.centerIn: parent text: qsTr("This is Sample Panel!") } } } main.qml import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 ApplicationWindow { SplitView { id: innerPanel Layout.preferredHeight: parent.height Layout.preferredWidth: parent.width SplitView { id: firstChartPanleItem } } property int count : 1; // count for control the splite number and check it is initial splitView function spliter(orientation, parentItem) { var chartPanelComponentOne var chartPanelComponentTwo var chartPanelItemOne var chartPanelItemTwo chartPanelComponentOne = Qt.createComponent("SamplePanel.qml"); chartPanelComponentTwo = Qt.createComponent("SamplePanel.qml"); if (count === 1){ chartPanelItemOne = chartPanelComponentOne.createObject(innerPanel); chartPanelItemTwo = chartPanelComponentTwo.createObject(innerPanel); if (orientation === "hor") { console.log(orientation); innerPanel.orientation = Qt.Horizontal; // set the parent orientation innerPanel.removeItem(firstChartPanleItem) count++ chartPanelItemOne.SplitView.minimumWidth = .3 * innerPanel.width; chartPanelItemOne.SplitView.preferredWidth = .5 * innerPanel.width; chartPanelItemTwo.SplitView.minimumWidth = .3 * innerPanel.width; chartPanelItemTwo.SplitView.preferredWidth = .5 * innerPanel.width; } else if (orientation === "ver"){ console.log(orientation); count++ innerPanel.orientation = Qt.Vertical; // set the parent orientation innerPanel.removeItem(firstChartPanleItem) chartPanelItemOne.SplitView.minimumHeight = .3 * innerPanel.height; chartPanelItemOne.SplitView.preferredHeight = .5 * innerPanel.height; chartPanelItemTwo.SplitView.minimumHeight = .3 * innerPanel.height; chartPanelItemTwo.SplitView.preferredHeight = .5 * innerPanel.height; } } else { chartPanelItemOne = chartPanelComponentOne.createObject(parentItem); chartPanelItemTwo = chartPanelComponentTwo.createObject(parentItem); if (orientation === "hor") { count++ parentItem.parent.orientation = Qt.Horizontal; // set the parent orientation parentItem.children[0].destroy() parentItem.children[1].destroy() chartPanelItemOne.SplitView.minimumWidth = .3 * parentItem.width; chartPanelItemOne.SplitView.preferredWidth = .5 * parentItem.width; chartPanelItemTwo.SplitView.minimumWidth = .3 * parentItem.width;; chartPanelItemTwo.SplitView.preferredWidth = .5 * parentItem.width; } else if (orientation === "ver"){ count++ parentItem.parent.orientation = Qt.Vertical; // set the parent orientation parentItem.children[0].destroy() parentItem.children[1].destroy() chartPanelItemOne.SplitView.minimumHeight = .3 * parentItem.height; chartPanelItemOne.SplitView.preferredHeight = .5 * parentItem.height; chartPanelItemTwo.SplitView.minimumHeight = .3 * parentItem.height; chartPanelItemTwo.SplitView.preferredHeight = .5 * parentItem.height; } } } }
  • Is there a way to create a model for TreeView in pure Qml (without using C++)

    Solved
    4
    0 Votes
    4 Posts
    332 Views
    Serhan KarsS
    Dear @Axel-Spoerl Thanks for the answer. Which part of documentation are you referring to? The comment section? // The model needs to be a QAbstractItemModel // model: yourTreeModel
  • bug in a JS function

    Solved
    17
    0 Votes
    17 Posts
    1k Views
    JKSHJ
    Actually, I don't think it's a bug after all. Basically: Your replaceValve() function is a "member" of your delegate. (More precisely, replaceValve() exists within the context of your valveBox delegate, which is separate from the context of EquipmentSelectValves by default) That function modifies the ListView's model. Modifying the model caused your delegate (and its context) to be destroyed. Destroying the delegate's context invalidates the references inside replaceValve(). Here is a minimal reproducer for your issue: //pragma ComponentBehavior: Bound import QtQuick import QtQuick.Controls.Basic Window { width: 800 height: 600 visible: true ListView { id: lv anchors.fill: parent model: 1 delegate: Button { text: "Click me" onClicked: { console.log("parent: " + parent) console.log("lv: " + lv) lv.model = 0 console.log("parent: " + parent) console.log("lv: " + lv) } Component.onDestruction: console.log("Destroyed", this) } } } Output: qml: parent: QQuickItem(0x1257086c4a0) qml: lv: QQuickListView(0x12570653350) qml: Destroyed Button_QMLTYPE_1(0x12570653b30) qml: parent: null Main.qml:22: ReferenceError: lv is not defined pragma ComponentBehavior: Bound changes QML's behaviour and puts replaceValve() inside the same context as EquipmentSelectValves, so you get the outcome that you expect. Qt can't make this the default yet because it will break old user code. But https://doc.qt.io/qt-6/qtqml-documents-structure.html#componentbehavior does say "The default value of ComponentBehavior is Unbound.... In a future version of Qt the default will change to Bound." I haven't visited Monterey before, but I'll give you a buzz if I'm ever in town. That seafood sounds tempting ;-)
  • Unexpected behavior using Repeater QML type

    Unsolved
    2
    0 Votes
    2 Posts
    197 Views
    A
    The QML code is import QtQuick import QtQuick.Controls Window { width: 640 height: 250 visible: true title: qsTr("Mac OS Dock Examples") Column { Slider { id: foff from: 1 to: 5 stepSize: 1 value: 2 snapMode: Slider.SnapAlways visible: false } Slider { id: sf from: 0.5 to: 2.5 stepSize: 0.5 value: 0.5 snapMode: Slider.SnapAlways visible: false } Slider { id: dmp from: 1 to: 5 stepSize: 1 value: 1 snapMode: Slider.SnapAlways visible: false } } Row { id: row anchors.bottom: parent.bottom anchors.bottomMargin: 30 anchors.horizontalCenter: parent.horizontalCenter property int falloff: foff.value // how many adjacent elements are affected property int current: -1 property real scaleFactor: sf.value // that's how much extra it scales property real damp: dmp.value // decay of influence Repeater { id: iconRepeater model: 10 Rectangle { width: 50 * pseudoScale height: width anchors.bottom: parent.bottom color: "red" border.color: "black" property real pseudoScale: { if (row.current == -1) return 1 else { var diff = Math.abs(index - row.current) diff = Math.max(0, row.falloff - diff) var damp = row.falloff - Math.max(1, diff) var sc = row.scaleFactor if (damp) sc /= damp * row.damp diff = diff / row.falloff * sc + 1 return diff } } MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true onContainsMouseChanged: row.current = containsMouse ? index : -1 } Behavior on pseudoScale { PropertyAnimation { duration: 150 } } } } } Row { anchors { top: parent.top horizontalCenter: parent.horizontalCenter } Repeater { id: rep model: ['red', 'yellow', 'pink', 'green', 'teal', 'orchid', 'blue', 'orange'] property int currentIndex: -10 delegate: Rectangle { anchors.top: parent.top // Calculate the width depending on the currently hovered element width: (rep.currentIndex === index ? 100 : ((rep.currentIndex - index) === 1 || (rep.currentIndex - index) === -1 ? 80 : 50)) height: width radius: width / 2 color: modelData MouseArea { anchors.fill: parent hoverEnabled: true // onEntered/Exited did not react. This will work. onContainsMouseChanged: { if (containsMouse) rep.currentIndex = index else rep.currentIndex = -10 // -10 is safe } } // Makes the movement smooth Behavior on width { NumberAnimation {} } } } } } with the main file #include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/MacDockOrig/Main.qml")); QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
  • Qt Creator will not find QML Unit Tests

    Unsolved
    5
    2 Votes
    5 Posts
    957 Views
    A
    @qiqi99 Check out my solution.
  • Can QtQuick app create and display MessageDialog from C++ static member function?

    Solved
    5
    0 Votes
    5 Posts
    513 Views
    Tom assoT
    @Bob64 - Thanks, Bob. Emitter actually emits a signal sendMsg(). The reason that connect() failed is because I need to specify data passed as QVariant (not QMessage) when data is exchanged between C++ and QML. So the following compiles and connects properly: Emitter.h: class Emitter : public QObject { signal: sendMsg(QVariant msg); }; main.cpp: QObject::connect(&backend.emitter, SIGNAL(sendMsg(QVariant)), rootObject, SLOT(showInfoDialog(QVariant))); My application includes a lot of legacy 'C' code, and passes Backend static function pointers to that C code. Now that I have it working it seems ok. Thanks!
  • QML charts gridline styling

    Unsolved
    1
    0 Votes
    1 Posts
    360 Views
    No one has replied
  • Slider support for tickmarks?

    Unsolved
    9
    0 Votes
    9 Posts
    845 Views
    Pl45m4P
    @GrecKo That's what I meant... the documentation shows the tick marks in some subsection
  • Is it possible to assign different types to a role in a ListElement ?

    Unsolved
    3
    0 Votes
    3 Posts
    368 Views
    L
    @Axel-Spoerl Thank you. Actually, I've found that putting a string also works : ListElement { display: "1" ... }
  • About QT

    Solved
    5
    0 Votes
    5 Posts
    389 Views
    T
    @johngod thanks a lot!
  • QML Threaded Animation

    Solved
    2
    0 Votes
    2 Posts
    280 Views
    beeckscheB
    A different image, but same effect. Fixed it with the BusyIndicator class. Button { text: "Run Blocking Function in C++" onPressed: busyIndicator.running = true onClicked: MyObjectInCpp.start() } BusyIndicator { id: busyIndicator running: false Connection { target: MyObjectInCpp function onFinished() { busyIndicator.running = false } } }
  • Qt Creator Build Failure - Fails to Clone Repository for New Qt Quick Application

    Unsolved
    7
    0 Votes
    7 Posts
    1k Views
    SGaistS
    @firen I am not aware of such a page but you are not alone having that issue.
  • Link failed when using QQuickMaterialStyle in Qt6.4

    Unsolved
    1
    0 Votes
    1 Posts
    162 Views
    No one has replied
  • QML Warnings

    Solved
    7
    0 Votes
    7 Posts
    744 Views
    GrecKoG
    @Veltroniv the preferred Connections syntax is now: Connections { function onLoginCorrect(token) { console.log("Token: ", token); } }
  • How to order object creation

    Solved
    4
    0 Votes
    4 Posts
    506 Views
    JKSHJ
    @mzimmers said in How to order object creation: I can just use outcome directly (which is preferable). Please don't do that! That is called "unqualified access", which prevents the QML compiler from optimizing your code. See https://www.qt.io/blog/compiling-qml-to-c-fixing-unqualfied-access for a discussion about unqualified access See https://www.qt.io/blog/the-numbers-performance-benefits-of-the-new-qt-quick-compiler for a peek at the optimization Use property bindings correctly (without doing special construction and assignment in Component.onCompleted) and you should get things the right order: // main.qml Window { id: window property Outcome outcome: outcomeComponent.createObject(window) as Outcome Component { id: outcomeComponent Outcome {} } ListView { delegate: VspEdit { outcome: window.outcome } } } // VspEdit.qml ColumnLayout { id: vspEdit required property Outcome outcome Component.onCompleted: console.log(vspEdit.outcome) } Notice that I fully qualify my variables (window.outcome, vspEdit.outcome) property var outcome Use the actual type instead of var for more optimization (and also so that modern tools like qmllint can scan your code and help you find any issues)
  • How to clear Settings (QtCore) from inside QML?

    Unsolved
    3
    0 Votes
    3 Posts
    375 Views
    johngodJ
    @Ntachy I did this by creating my own clear function (I name it reset() ), where I set all the properties to their default values. In my case I had a button where the user would click to reset the values, dont know your use case, where you would called it is up to you. If you want to clear the values "outside" the running app, check here for where the values are stored: https://doc.qt.io/qt-6/qsettings.html#platform-specific-notes
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied