Skip to content
Qt 6.12 LTS is out! See what's new in the release blog
  • 145k Topics
    725k Posts
    GilboonetG
    the data class #ifndef PIECE_H #define PIECE_H #include <QtCore/qobjectdefs.h> #include <QtCore/qtmetamacros.h> class piece { Q_GADGET Q_PROPERTY(float x READ x WRITE setX) Q_PROPERTY(float y READ y WRITE setY) public: piece() : m_x(0.0f), m_y(0.0f) {} piece(const piece &) = default; piece(piece &&) = default; piece &operator=(const piece &) = default; piece &operator=(piece &&) = default; explicit piece(const float &x, const float &y) : m_x(x), m_y(y) {} void setX(float newX) { if (!qFuzzyCompare(newX, m_x)) m_x = newX; } void setY(float newY) { if (!qFuzzyCompare(newY, m_y)) m_y = newY; } private: float m_x; float m_y; float x() const { return m_x; } float y() const { return m_y; } }; #endif // PIECE_H main.cpp #include "piece.h" #include <QRangeModel> #include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QList<piece> mesPieces; mesPieces.append(piece(20.0f, 20.0f)); mesPieces.append(piece(60.0f, 0.0f)); mesPieces.append(piece(100.0f, 30.0f)); QRangeModel modele(&mesPieces); QQmlApplicationEngine engine; engine.setInitialProperties({{"monModele", QVariant::fromValue(&modele) }}); QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("testQRange1", "Main"); return QGuiApplication::exec(); } main.qml import QtQuick import QtQuick.Controls.Basic import QtQuick.Shapes ApplicationWindow { id: window width: 640 height: 480 visible: true title: qsTr("test QRangeModel") required property AbstractItemModel monModele Repeater { model : monModele Shape { property real mx : monModele.data(monModele.index(index, 0), Qt.DisplayRole) property real my : monModele.data(monModele.index(index, 1), Qt.DisplayRole) anchors.fill: parent ShapePath { strokeColor: "yellow" fillColor: "yellow" strokeWidth: 1 startX: mx startY: my PathLine { relativeX: 0; relativeY: 50 } PathLine { relativeX: 50; relativeY: 0 } } } } } It doesn't work if I try to replace mx and my properties by required property real x (and y)
  • Jobs, project showcases, announcements - anything that isn't directly development
    4k 23k
    4k Topics
    23k Posts
    SGaistS
    Hi, Nice ! Thanks
  • Everything related to designing and design tools

    133 403
    133 Topics
    403 Posts
    A
    Thanks a lot for all this information. It has helped me get clarity on the questions that have been bugging me for weeks. I can now decide better what I want to do, and why. I will definitely share these with them ideas about unifying the UI for mobile and desktop with Qt, as it seems like it doesn't necessarily warrant replacing starting their application from scratch, only their UI code will get replaced (and its bindings).
  • Everything related to the Software Quality Tools

    97 274
    97 Topics
    274 Posts
    C
    This had been reported to Squish technical support team, and closed on behalf of the reporter. Unfortunately it was not possible to identify a clear cause so far.
  • Everything related to learning Qt.

    403 2k
    403 Topics
    2k Posts
    A
    [image: 821a1523-0783-4de7-a4c6-3093de817dbe.png]
  • 2k Topics
    13k Posts
    jsulmJ
    @VikMorroHun said in blocked: cmake: command not found: In Linux I got more than 6000 hits How did you search to get 6000 hits?
  • 4k Topics
    18k Posts
    C
    找到原因了,账号密码错误导致的
  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k 10k
    1k Topics
    10k Posts
    P
    Unless I misunderstand, this topic was written when this forum used Textile, which explains why some of the above have broken formatting. This question is therefore no longer relevant for this forum. That being said, to anwer this question should anyone else land on this topic from a search engine, this should (now?) be possible. 🅭🄍