Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Loaded QQuickItem, how to set properties correct?
Forum Updated to NodeBB v4.3 + New Features

Loaded QQuickItem, how to set properties correct?

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jpcolcom
    wrote on last edited by
    #1

    How can i set the build in properties right?
    I create a QQuickItem via QQmlComponent:

    @LoadQuickItem::LoadQuickItem(QQmlEngine* engine, QQuickItem* parentView, QObject *parent) : QObject(parent) {

    this->engine_ = engine;
    this->parentView_ = parentView;
    this->component_ = new QQmlComponent(engine, QUrl("qrc:///Item.qml"));
    this->obj_ = new QObject();
    this->continueLoading();
    }

    LoadQuickItem::~LoadQuickItem() {
    delete this->component_;
    delete this->obj_;
    delete this->item_;
    }

    void LoadQuickItem::continueLoading() {
    if (this->component_->isError()) {
    qWarning() << this->component_->errors();
    } else {
    qDebug() << "Create QQuickItem";

      this->obj_ = this->component_->create();
      QQmlEngine::setObjectOwnership(this->obj_, QQmlEngine::CppOwnership);
      this->item_ = qobject_cast<QQuickItem*>(this->obj_);
    
      this->item_->setParentItem(this->parentView_);
      this
    

    }
    }@

    Instance:
    @
    QQuickWindow wnd;
    QQmlEngine engine;
    LoadQuickItem* item1 = new LoadQuickItem(&engine, wnd.contentItem());
    qDebug() << (item1->getItem()->setProperty("id", "item1") ? "Succes" : "Failed: item1->getItem()->setProperty("id", "item1")");
    @

    Item.qml

    @import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2

    Button {
    text:"Maximize"
    tooltip:"Press me"
    style: CustomStyle {}
    }@

    I want to set the property "id", but always get a false.
    The property ought to be known?

    Background, I would like load files via a QML and use them as templates. A QML file always contains only one control, eg a button.

    Any idear?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      id is not a property, it is not visible to public Qt API. You can not change it in C++. All remaining properties are available and you can change them as you wish.

      (Z(:^

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        From the Doc:

        bq. Once an object instance is created, the value of its id attribute cannot be changed. While it may look like an ordinary property, the id attribute is not an ordinary property attribute, and special semantics apply to it;

        So you can't change it.

        157

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jpcolcom
          wrote on last edited by
          #4

          Thanks.

          how can I implement a dependency between two QQuickitems?
          Like:

          @
          LoadQuickItem* item1 = new LoadQuickItem(&engine, wnd.contentItem());
          LoadQuickItem* item2 = new LoadQuickItem(&engine, wnd.contentItem());
          item2->getItem()->setProperty("y", "item1.height")
          @

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            You can use property() to get the height of other Item.

            157

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="p3c0" date="1409819479"]You can use property() to get the height of other Item.[/quote]

              I think the OP wants to create a property binding from C++.

              (Z(:^

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jpcolcom
                wrote on last edited by
                #7

                [quote author="p3c0" date="1409819479"]You can use property() to get the height of other Item.[/quote]

                Yes that works. But only in static way.

                I mean this construct, in case of resizing the window.
                @Button {
                id: button1
                width: parent.width / 100 * 20
                height: parent.height / 100 * 20
                }
                Button {
                id: button2
                width: parent.width / 100 * 20
                height: parent.height / 100 * 20
                y: button1.height
                }
                @

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  -Here is an example on property bindings in C++. "Link":http://qt-project.org/doc/qt-5/qtqml-tutorials-extending-chapter3-bindings-example.html.-

                  Nope, sorry, that is not good enough.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

                    Connect the heightChanged signal to a slot, then get the height of item1 and then setProperty to item2.

                    157

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved