Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k Topics 77.5k Posts
  • open new window on button click

    Unsolved
    3
    0 Votes
    3 Posts
    4k Views
    S
    //*** help button Button{ id: helpButton height: hButton text: qsTr("Help") onClicked:{ var component = Qt.createComponent("HelpForm.qml") var window = component.createObject() window.show() } } I hope this can help you ....
  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    30 Views
  • Exception with ChartView and ApplicationWindow

    Unsolved
    2
    0 Votes
    2 Posts
    422 Views
    Y
    I encountered the same problem. Did someone have a solution ?
  • Qt designer(in qt creator) crashes in wsl2

    Unsolved
    1
    1 Votes
    1 Posts
    372 Views
    No one has replied
  • 0 Votes
    2 Posts
    834 Views
    J
    As a workaround, I've overidden QWidget::event() in the QQuickWidget derived class (which loads the QML source above): bool MyQQuickWidget::event(QEvent* event) { if (isEnabled() && !isActiveWindow()) { activateWindow(); } return QQuickWidget::event(event); } This allows the TextField to receive focus from the touchscreen alone. I don't really understand why the window needs to be manually activated like this. I'm probably doing something wrong, but as it's just a prototype, I'm happy with the solution for now. If anyone would care to share some insight, I'd appreciate it.
  • module importation problem

    Solved
    8
    0 Votes
    8 Posts
    2k Views
    mzimmersM
    @sierdzio I think you're on to something here (though I haven't fixed it yet). In looking at the build settings, it appears that the QML_IMPORT_PATH variable is populated by this line in build/CMakeCache.txt: QML_IMPORT_PATH:STRING=/home/mzimmers/git/KOL-UI/qml;/home/mzimmers/git/KOL-UI/qml/dummydata;/home/mzimmers/git/KOL-UI/qml/priming;/home/mzimmers/git/KOL-UI/qml/running_synth;/home/mzimmers/git/KOL-UI/../libstyles;/home/mzimmers/git/KOL-UI/../libstyles/imports;/home/mzimmers/git/KOL-UI/../libstyles/imports/libstyles;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/imports I replaced a few entries to what I believe are correct paths: QML_IMPORT_PATH:STRING=/home/mzimmers/git/KOL-UI/qml;/home/mzimmers/git/KOL-UI/qml/dummydata;/home/mzimmers/git/KOL-UI/qml/priming;/home/mzimmers/git/KOL-UI/qml/running_synth;/home/mzimmers/git/KOL-UI/src/libstyles;/home/mzimmers/git/KOL-UI/src/libstyles/imports;/home/mzimmers/git/KOL-UI/src/libstyles/imports/libstyles;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/imports And I re-ran CMake, but this didn't solve the problem. I went ahead and manually changed the build settings, and this did solve the problem, though I imagine the next time I do whatever causes the CMakeCache.txt file to be re-read will wipe out those changes. EDIT: So, with the help of someone in the office, we figured out what to do here. This line (among others) was in the subordinate CMake file; we just moved it to the root CMake file: list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/libstyles) I'm not sure it was necessary to use CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR in this instance, but it's probably a good practice. Thanks for the help...
  • Convert PrincipledMaterial to CustomMaterial

    Unsolved
    1
    0 Votes
    1 Posts
    122 Views
    No one has replied
  • QQmlContext::setContextProperty and deleting objects

    Solved
    4
    0 Votes
    4 Posts
    2k Views
    fcarneyF
    For future reference my test setup to try and break context properties. main.cpp: #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include <QHash> #include <QRandomGenerator> #include <QObject> #include <QDebug> class ContextSetter : public QObject { Q_OBJECT // test multiple context properties in one object Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) QString m_name; public: ContextSetter(QObject* parent=nullptr) : QObject(parent) {} QString name() const { return m_name; } public slots: void setName(QString name) { if (m_name == name) return; m_name = name; emit nameChanged(m_name); } signals: void nameChanged(QString name); }; class ContextHolder : public QObject { Q_OBJECT public: ContextHolder(QObject* parent=nullptr) : QObject(parent) , m_rootcontext(nullptr) { m_seededgen = QRandomGenerator::securelySeeded(); } void setrootcontext(QQmlContext* context){ m_rootcontext = context; } QQmlContext* rootcontext(){ return m_rootcontext; } public slots: QString createContextPropertyObject(QString name = QString()){ if(m_rootcontext){ char set = std::round(m_seededgen.generateDouble()) ? 'a' : 'A'; char head = set + std::floor(m_seededgen.generateDouble() * 26); // a to Z int body = std::round(m_seededgen.generateDouble() * 100000); QString propname; if(name.length()) propname = name; else propname = QString("%1%2").arg(head).arg(body); auto obj = new ContextSetter(this); obj->setName(propname); m_propobjects[propname] = obj; m_rootcontext->setContextProperty(propname, obj); qDebug() << "Created:" << propname; return propname; } return QString(); } void deleteContextPropertyObject(QString propname){ if(m_propobjects.contains(propname)){ auto obj = m_propobjects[propname]; m_propobjects.remove(propname); obj->deleteLater(); m_rootcontext->setContextProperty(propname, nullptr); qDebug() << "Deleted:" << propname; } } private: QQmlContext* m_rootcontext; QHash<QString, QObject*> m_propobjects; QRandomGenerator m_seededgen; }; int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; auto rootcontext = engine.rootContext(); ContextHolder cholder; cholder.setrootcontext(rootcontext); rootcontext->setContextProperty("contextholder", &cholder); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); } #include "main.moc" main.qml: import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Window 2.12 Window { id: mainwin width: 640 height: 480 visible: true title: qsTr("setContextProperty object deletion testing") property var proplist: [] Timer { id: createtimer interval: 1000 repeat: true running: true onTriggered: { var propname = contextholder.createContextPropertyObject() proplist.push(propname) } } Timer { id: deletetimer interval: 1000 repeat: true running: true onTriggered: { var propname = proplist.pop() contextholder.deleteContextPropertyObject(propname) } } Timer { id: cycledialog interval: 500 repeat: true running: true property string propname: "KillMe" Component.onCompleted: { contextholder.createContextPropertyObject(propname) contextholder.deleteContextPropertyObject(propname) } onTriggered: { contextholder.createContextPropertyObject("Atestobject") contextholder.createContextPropertyObject("atestobject") contextholder.createContextPropertyObject("Ztestobject") contextholder.createContextPropertyObject("ztestobject") contextholder.createContextPropertyObject("Qtestobject") contextholder.createContextPropertyObject("qtestobject") testdialogloader.active = true } } Loader { id: testdialogloader active: false sourceComponent: testdialog } Component { id:testdialog Rectangle { width: 200 height: 200 color: "red" Column { Text { text: Atestobject.name } Text { text: atestobject.name } Text { text: Ztestobject.name } Text { text: atestobject.name } Text { text: Qtestobject.name } Text { text: qtestobject.name } Text { text: "propname: " + KillMe } } Timer { id: disabletimer interval: 250 repeat: false running: true onTriggered: { testdialogloader.active = false contextholder.deleteContextPropertyObject("Atestobject") contextholder.deleteContextPropertyObject("atestobject") contextholder.deleteContextPropertyObject("Ztestobject") contextholder.deleteContextPropertyObject("ztestobject") contextholder.deleteContextPropertyObject("Qtestobject") contextholder.deleteContextPropertyObject("qtestobject") } } } } } Notice if you comment out: m_rootcontext->setContextProperty(propname, nullptr); Then it will crash on accessing the KillMe context property. So setting a previously used context property to nullptr is a way to protect yourself from seg faults.
  • Qt3D - STL/PLY/OBJ meshes not showing up

    Unsolved
    1
    0 Votes
    1 Posts
    388 Views
    No one has replied
  • Reference a QML object id from a JavaScript function

    Unsolved
    4
    0 Votes
    4 Posts
    362 Views
    B
    I get "Unreachable (M28)" message at the line where I do rect.color = "black"; This happens if I keep the function within the Rectangle Object or outside. That's why I am confused. Just to clarify what I am trying to do. I have a slider that changes the color of another object. Once I change the color, I store that color RGB in a db. Once I restart the app, I want to set the slider to the stored RGB color, and the slider to the same RGB value. So I have the function, called rgbToHsl, that gets as input the HEX value of color, it converts to HSL, and returns the value to the slider. But some how when I do reference the slider and I assign the value, I get that error. The slider has property color colorValue, so I am trying to set the colorValue like rect.color = colorValue
  • Detect when C++ method called from QML. How?

    Solved
    3
    0 Votes
    3 Posts
    345 Views
    B
    @KroMignon Thx. Issue closed. Will do parameter like always.
  • How to get a selected item from QListView delegated?

    Unsolved
    2
    0 Votes
    2 Posts
    336 Views
    SGaistS
    Hi, That's not responsibility of the delegate. Use a custom mime type to provide the information needed and do the insertion at the drop point.
  • "Smart" content for TextDocument with C++, QTextDocument, and QML TextEdit

    Unsolved
    2
    0 Votes
    2 Posts
    340 Views
    J
    Aha! Given a TextEdit named textEdit, I can insert Qt's rich text HTML subset through textEdit.insert. In combination with textEdit.remove, effectively replacing existing text with re-formatted text. This is a (minimal) answer to my own question. Unfortunately, since I can't use a QTextCursor::beginEditBlock and endEditBlock with this solution, I can't prevent the remove+insert from adding two items to the QTextDocument's "undo" history. That's a bit messy, but I can live with it if I know I'll be able to fix it later - whether by being able to replace a document fragment in a single undoable op, or by overriding the built-in "undo/redo" feature with my own. I appreciate how the simplicity of a minimal API makes it easier to implement radical changes to the implementation of Quick Controls, and I love what's been accomplished in Qt's Quick Controls. Figuring out how to get what in this case is a bit of a puzzle, but as a beginner here I'm sure there are many interesting solutions I haven't thought of yet.
  • Switch shown windows by changing integer in additional .qml file

    Unsolved
    1
    0 Votes
    1 Posts
    226 Views
    No one has replied
  • Multiple windows

    Unsolved
    1
    0 Votes
    1 Posts
    167 Views
    No one has replied
  • How to manually activate CheckBox blue focus indicator ?

    Solved checkbox qml quick quick controls
    2
    0 Votes
    2 Posts
    744 Views
    M
    Problem solved by calling chekbox.forceActiveFocus(Qt.TabFocusReason)
  • STM32F769I-DISCO Flicker issue

    Unsolved
    2
    0 Votes
    2 Posts
    217 Views
    Pablo J. RoginaP
    @Khushboo I understand that Qt for MCU needs a commercial license, so you may want to check with the Qt Company directly for support with such component.
  • Missing languages for qtbase and qtdeclarative files

    Unsolved
    3
    0 Votes
    3 Posts
    747 Views
    S
    Thanks for the insights. We will check for missing translations and consider contributing :) Best Stephan
  • Qml ComboBox and current model item

    Solved
    5
    0 Votes
    5 Posts
    2k Views
    SiN_BizkitS
    @GrecKo In case if I will manually extend my model's public interface in that way I will lost the possibility to chain models (e.g. set qsortfilterproxymodel in front of my model). I decided to expose my custom Roles to the qml part and fetch the data via QAbstractItemModel::data method by hand. function getModelKeyByRow(model, row) { let modelIndex = model.index(row, 0); return model.data(modelIndex, QtExtras.KeyValueModel.KeyRole); } I thought maybe there is some more convenient way :) But I'm absolutely fine with it right now. Someday I will upgrade Qt to 5.14 and the problem will disappear. Thank you folks!
  • QML module not found (QtQuick.Studio.Components 1.0 )

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