Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] QPaintedItem : Update don't call paint()

    QML and Qt Quick
    2
    10
    4681
    Loading More Posts
    • 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.
    • R
      Remi73 last edited by

      Hi!
      I'm trying to do something like this tuto : http://qt-project.org/doc/qt-5/qtquick-customitems-painteditem-example.html
      But with an explicit use of update function in c++. update() never call paint()...

      Part of code :
      C++ :

      • header
        @class KLeapFinger : public QQuickPaintedItem {

        Q_OBJECT

      public:
      KLeapFinger(QQuickItem * parent = 0);
      void paint(QPainter * painter);

      public slots:
      void drawPointables(QVector<QPoint> pointList);

      private:
      QVector<QPoint> m_pointList;

      };@

      • Source
        @////////////////////////////////////////////////////////////////
        //////////////////// CLASS KLEAPFINGER /////////////////////////
        ////////////////////////////////////////////////////////////////
        KLeapFinger::KLeapFinger(QQuickItem *parent) : QQuickPaintedItem(parent)
        {
        this->setFlag(QQuickItem::ItemHasContents, true); // No visible change with or without
        }

      ////////////////////////////////////////////////////////////////
      void KLeapFinger::drawPointables(QVector<QPoint> pointList)
      {
      qDebug() << "KLeapFinger::drawPointables"; // well display
      m_pointList = pointList;

      update();
      qDebug() << contentsBoundingRect(); // QRectF(0,0 0x0)
      qDebug() << contentsSize(); // QSize(-1, -1)
      

      }

      ////////////////////////////////////////////////////////////////
      void KLeapFinger::paint(QPainter *painter)
      {
      qDebug() << "paint !!" << m_pointList.first(); // Never display (except one time at the start, or when resize the windows)
      QVector<QPoint>::iterator it;
      for(it = m_pointList.begin() ; it < m_pointList.end() ; it++)
      {
      painter->setPen(Qt::white);
      painter->drawEllipse(*it, 25, 25);
      qDebug() << *it;
      }
      }

      ////////////////////////////////////////////////////////////////
      /////////////// END OF CLASS KLEAPFINGER ///////////////////////
      ////////////////////////////////////////////////////////////////@

      QML :
      @ KLeapFinger {
      id: fingerPainter
      anchors.fill: parent
      }@

      Thank a lot !

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi,

        Welcome. Can you show where do you call drawPointables() ?

        157

        1 Reply Last reply Reply Quote 0
        • R
          Remi73 last edited by

          Hi, thank!

          I'm using a signal, which is emit regulary (maybe 10 time/sec)

          @m_kLeapFinger = new KLeapFinger();
          connect(this, SIGNAL(drawPointables(QVector<QPoint>)),m_kLeapFinger, SLOT(drawPointables(QVector<QPoint>)));
          @
          @emit drawPointables(pointList);@

          1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators last edited by

            Well i see something fishy here. Your SLOT is same as that of SIGNAL. Is that a typo ? Have you declared the SIGNAL in header ? Since i don't see it in the code pasted above.

            157

            1 Reply Last reply Reply Quote 0
            • R
              Remi73 last edited by

              To be sure I change the name...
              Yes the signal is well declared, I don't think the problem is here. As I wrote in comment in my code, qDebug() is well display in the slot, and well display in the paint ONLY when I resize the windows, never when I call update()..

              1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators last edited by

                Ok, Can you show how have you registered KLeapFinger component ? in main.cpp ?

                157

                1 Reply Last reply Reply Quote 0
                • R
                  Remi73 last edited by

                  Main:
                  @qmlRegisterType<KLeapFinger>("KLeap", 1, 0, "KLeapFinger");@

                  QML:
                  @import KLeap 1.0@

                  1 Reply Last reply Reply Quote 0
                  • p3c0
                    p3c0 Moderators last edited by

                    IMO, the problem here is the KLeapFinger which you are using in the QML and the one which you have created using new are totally different. And you have connected signals to the KLeapFinger that was created using new and not the KLeapFinger used in QML.
                    You can declare a timer in the KLeapFinger class itself or use a timer in the QML and call the function which then calls update.

                    157

                    1 Reply Last reply Reply Quote 0
                    • R
                      Remi73 last edited by

                      That's it ! Thank you !
                      (I made the connection between c++ object in the QML)

                      1 Reply Last reply Reply Quote 0
                      • p3c0
                        p3c0 Moderators last edited by

                        Ok.
                        You're Welcome. Happy Coding :)

                        157

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post