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. [SOLVED] QPaintedItem : Update don't call paint()
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 2 Posters 5.3k Views
  • 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 Offline
    R Offline
    Remi73
    wrote on last edited by
    #1

    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
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

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

      157

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Remi73
        wrote on last edited by
        #3

        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
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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
          0
          • R Offline
            R Offline
            Remi73
            wrote on last edited by
            #5

            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
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

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

              157

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Remi73
                wrote on last edited by
                #7

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

                QML:
                @import KLeap 1.0@

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

                  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
                  0
                  • R Offline
                    R Offline
                    Remi73
                    wrote on last edited by
                    #9

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

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

                      Ok.
                      You're Welcome. Happy Coding :)

                      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