Skip to content
  • 0 Votes
    5 Posts
    608 Views
    johngodJ

    @GrecKo Thanks for the tips.
    Initially I had a QList with c++ objects, but now for simplicity I am trying to avoid that. To manage the dynamic objects, each has a signal connection when they are created. Then when something happens, they receive signals and each object manage it self (turns visible, unvisible, gets deleted, ....). I think this approach it is much easier than creating filters and lists or repeaters.

  • 0 Votes
    2 Posts
    264 Views
    TobiasT

    I got an answer that fixes the problem on Stackoverflow https://stackoverflow.com/a/75522782/5134351

  • 0 Votes
    4 Posts
    580 Views
    M

    Would switching to a QAbstractListModel (you'll get roles instead of columns to define your data) and using a Repeater with a custom delegate work in your usecase?

    Whether it's a list or a table model doesn't matter much. The number of columns is fixed, so a list model (using roles instead of columns) is fine. This is actually a separate question I wanted to ask in another thread... I don't really understand the concept of "roles." I keep googling it to find more explanations but none of them make sense to me for some reason.

    The bigger issue is that I don't think I understand how to use a Repeater for this, if what I really need to do is draw something on a canvas for each of the items in the list (or for each row in the table). Can a repeater be used that way?

    That's because *Views already have the basic plumbing to connect to a model in place [...] just design a component that react to those signals.

    I think that's the part I was having trouble verbalizing, thank you for attaching the right words to it!

    Just to make sure I actually understand the methodology, let me type out a scenario and make sure it passes a sanity check. Let's say that I have my subclass of QAbstractTableModel, which, like all descendants of QAbstractItemModel, emits those signals. What I need to do is develop a QML component that connects to those signals. Here's where I'm a little weak in my understanding... It seems to me that there are two things I need to do:

    Somehow declare a model for the component, where the model is some QAbstractItemModel object in the context of my QQmlApplicationEngine Declare onDataChanged for my custom component, and it will automatically be connected to the dataChanged signal that gets emitted from that QAbstractItemModel object

    Is that correct, and if so, how do I declare the model object for my custom component? ListView and TableView do this through a delegate model, which, as I mentioned above, I'm not sure I know how to use to draw things on a canvas.

    Thanks for the help, @GrecKo and @VRonin!

  • 0 Votes
    1 Posts
    779 Views
    No one has replied
  • 0 Votes
    1 Posts
    725 Views
    No one has replied
  • 0 Votes
    1 Posts
    358 Views
    No one has replied
  • 0 Votes
    1 Posts
    301 Views
    No one has replied
  • 0 Votes
    5 Posts
    2k Views
    E

    This is how I style one off BusyIndicator:

    BusyIndicator { running: true Component.onCompleted: { contentItem.pen = "white" contentItem.fill = "white" } }

    If I recall correctly I was looking at source code of BusyIndicator to understand how to style it.

  • 0 Votes
    6 Posts
    4k Views
    Q

    @Ronak5 no, I didn't. that's probably not the problem any current test is trying to share a bool with QML and the problem is the same. but I'll remember to try it when sharing a string :)

    So here is a simpler project and use a Singleton. One of the problem was that I have to declare my object in the QML when using qmlRegisterType. And I don't want to. So here is the new code, the error is the same.
    I followed the example of the doc here https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html

    miniModel.h (the singleton)

    #ifndef _MINIMODEL_H_ #define _MINIMODEL_H_ #include <stdlib.h> #include <stdio.h> #include <iostream> #include <string> #include <QtGui/qguiapplication.h> #include <QtQml/qqmlcontext.h> #include <QtQml/qqmlapplicationengine.h> #include <QtCore/qdebug.h> #include <QtCore/qobject.h> #include <QtCore/qvariant.h> class MiniModel : public QObject { Q_OBJECT Q_PROPERTY(bool miniboule READ miniboule WRITE setMiniboule NOTIFY minibouleChanged) public: MiniModel(); bool miniboule(); void setMiniboule(bool bouboule); signals: void minibouleChanged(); private: bool m_miniboule; }; #endif

    main.cpp v1 : singleton using a QObject

    #include "miniModel.h" //defining a miniModel instance as a singleton static QObject* mp_singleton(QQmlEngine* engine, QJSEngine* scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) MiniModel* miniSingleton = new MiniModel(); return miniSingleton; } int main(int argc=0, char* argv[]=nullptr) { printf("\n launching \n"); QGuiApplication app(argc, argv); qmlRegisterSingletonType<MiniModel>("myModel.miniModel", 1, 0, "MiniModel",mp_singleton); QQmlApplicationEngine engine; engine.addImportPath(QStringLiteral("..\\..\\..\\..\\Tools\\Qt\\5.12.0\\x64\\5.12.0\\msvc2017_64\\qml")); engine.load(QUrl(QStringLiteral("..\\..\\..\\miniModel.qml"))); return app.exec(); }

    main.cpp v2 : singletin using QJSValue

    #include "miniModel.h" static QJSValue m_singletonModel(QQmlEngine* engine, QJSEngine* scriptEngine) { Q_UNUSED(engine) static bool m_miniboule; QJSValue miniModel = scriptEngine->newObject(); miniModel.setProperty("miniboule", m_miniboule); return miniModel; } int main(int argc = 0, char* argv[] = nullptr) { printf("\n launching \n"); QGuiApplication app(argc, argv); qmlRegisterSingletonType("myModel.miniModel", 1, 0, "MiniModel", m_singletonModel); QQmlApplicationEngine engine; engine.addImportPath(QStringLiteral("..\\..\\..\\..\\Tools\\Qt\\5.12.0\\x64\\5.12.0\\msvc2017_64\\qml")); engine.load(QUrl(QStringLiteral("..\\..\\..\\miniModel.qml"))); return app.exec(); }

    and the QML. be careful, it's tough

    import QtQuick 2.5 import QtQuick.Window 2.5 import QtQuick.Controls 1.4 import myModel.miniModel 1.0 as MyModel ApplicationWindow { id: root width: 300 height: 480 visible:true Text{ id: textTest x: 62 y: 75 color: "#d21616" text: "vanilla" visible: false//the text is supposed to appear when clicking in the mouseArea } MouseArea{ anchors.fill: parent onClicked: textTest.visible= MyModel.Minimodel.miniboule//the boolean I want to acess, defined to true } }

    now, the error changed, since I called MyModel.MiniModel.miniboule instead of just MiniModel.miniboule
    the error is TypeError: Cannot read property 'miniboule' of undefined

  • 0 Votes
    5 Posts
    2k Views
    S

    If you need this for just measuring the performance of your application, maybe you should use the QML Profiler instead http://doc.qt.io/qtcreator/creator-qml-performance-monitor.html

  • QML ComboBox Popup Issue

    Unsolved QML and Qt Quick
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    2 Posts
    955 Views
    timdayT

    @seyed As I understand things, you need to get hold of the item's transform and do whatever your rendering needs to do with it for it to have effect... see https://stackoverflow.com/questions/28535528/how-can-i-get-transform-matrix-for-qquickitem . (Similarly, nothing will implement the opacity property for you... you have to bring it into your OpenGL code and use it in your fragment shader.)

  • 0 Votes
    2 Posts
    799 Views
    sierdzioS

    Use model classes and views instead of such approach. It will save you a lot of tears in the long run.

    For a starter, see: https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

  • 0 Votes
    1 Posts
    586 Views
    No one has replied
  • 0 Votes
    2 Posts
    1k Views
    S

    @pra7 Follow these instructions then edit your styles.qml file and comment out line 437

    spaceKeyPanel: KeyPanel { Rectangle { id: spaceKeyBackground radius: 5 color: "#35322f" anchors.fill: parent anchors.margins: keyBackgroundMargin Text { id: spaceKeyText //text: Qt.locale(InputContext.locale).nativeLanguageName
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    5 Posts
    4k Views
    E

    @pra7 See also https://forum.qt.io/topic/82700/datepicker-anyone. BTW you must mean Quick Controls 2, not QML2. You also can use Controls 1 elements in Controls 2 application, although the look&feel may be a problem.

  • 0 Votes
    2 Posts
    1k Views
    P

    I got to know that there is no such API to set Screen orientation in QT for windows and thus I used windows API for locking app Orientation, following is the code :

    Just copy paste below code in main.cpp:

    #include <Windows.h> typedef enum ORIENTATION_PREFERENCE { ORIENTATION_PREFERENCE_NONE = 0x0, ORIENTATION_PREFERENCE_LANDSCAPE = 0x1, ORIENTATION_PREFERENCE_PORTRAIT = 0x2, ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4, ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8 } ORIENTATION_PREFERENCE; typedef BOOL (WINAPI *pSDARP)(ORIENTATION_PREFERENCE orientation); pSDARP pARP; pARP = (pSDARP) GetProcAddress( GetModuleHandle(TEXT("user32.dll")), "SetDisplayAutoRotationPreferences"); if( pARP ){ pARP( (ORIENTATION_PREFERENCE)(ORIENTATION_PREFERENCE_LANDSCAPE | ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED ) ); }

    For more information please refer : Handling Windows Auto-rotate feature in your application Hope it helps others .