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. onPaint event not triggered twice

onPaint event not triggered twice

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 2 Posters 881 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.
  • I Offline
    I Offline
    itzwich1
    wrote on last edited by
    #1

    Hallo,

    I try to build my own spinBox. Now I draw my Up & Down Arrow buttons with Canvas which draw the arrows in the onPaint event.

    Now the Problem

    mainWindow.qml // Window where I would like to use my SpinBox
    {
         OwnSpinBox{
              width: 100
              height: 20
              value: 20 //It works (Both of my Up&Down Arrows will draw with onPaint
              Component.onCompleted:{
                   value: 20   //Works not (Only one of both Arrows will draw with onPaint
              }
         }
    }
    

    Component.onCompleted: value: 20
    e1bfb947-fbb9-48be-8135-a88abebfca2a-image.png

    value: 20
    0ee70241-01d9-4e4c-8468-6152cd238b8d-image.png

    It looks like that onPaint event works only once in ColumLayout. But only value will set in Component.onCompleted

    value is a int which will checks in a cpp class if its valid. Is it valid da int will converted to a string and will write to the textInput as text.

    My Cpp class inherits from QQuickItem.

    Hope anybody can help me.

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

      @itzwich1 said in onPaint event not triggered twice:

      Component.onCompleted:{
      value: 20 //Works not (Only one of both Arrows will draw with onPaint
      }

      This syntax is incorrect. It should be:

       Component.onCompleted:{
                     value = 20
                }
      

      (Z(:^

      I 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @itzwich1 said in onPaint event not triggered twice:

        Component.onCompleted:{
        value: 20 //Works not (Only one of both Arrows will draw with onPaint
        }

        This syntax is incorrect. It should be:

         Component.onCompleted:{
                       value = 20
                  }
        
        I Offline
        I Offline
        itzwich1
        wrote on last edited by
        #3

        @sierdzio sorry thats my mistake. I said (value = 20)

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

          Assignment like this (with =) breaks bindings (with :). So, if you rely on some property to set the value (like value: someOtherValue), don't add override in onCompleted.

          (Z(:^

          I 1 Reply Last reply
          0
          • sierdzioS sierdzio

            Assignment like this (with =) breaks bindings (with :). So, if you rely on some property to set the value (like value: someOtherValue), don't add override in onCompleted.

            I Offline
            I Offline
            itzwich1
            wrote on last edited by
            #5

            @sierdzio I do not use both versions at the same time. If I use the value: 20 it works fine and my up and down arrows will painted. If I use (Component.onCompleted: value = 20) instead of (value: 20) it doesn't work.

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

              OK, now I begin to understand :-) Try forcing a repaint in your setter for value property (in C++).

              (Z(:^

              I 1 Reply Last reply
              0
              • sierdzioS sierdzio

                OK, now I begin to understand :-) Try forcing a repaint in your setter for value property (in C++).

                I Offline
                I Offline
                itzwich1
                wrote on last edited by
                #7

                @sierdzio How can I trigger onPaint event on c++ side?

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

                  You can call updatePaintNode(yourMainNode, nullptr); if you have the main node stored somewhere. Alternatively, mark the node as dirty https://doc.qt.io/qt-5/qsgnode.html#markDirty

                  (Z(:^

                  I 1 Reply Last reply
                  0
                  • sierdzioS sierdzio

                    You can call updatePaintNode(yourMainNode, nullptr); if you have the main node stored somewhere. Alternatively, mark the node as dirty https://doc.qt.io/qt-5/qsgnode.html#markDirty

                    I Offline
                    I Offline
                    itzwich1
                    wrote on last edited by
                    #9

                    @sierdzio I think that solves not the problem. I try to use update() which call updatePaintNode in it (according the doku). Problem is still there.

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

                      Verify if it's called or not with debugger or qDebug.

                      Maybe paste the drawing code here, perhaps there's something wrong there?

                      (Z(:^

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        itzwich1
                        wrote on last edited by
                        #11

                        My colleague could help me. It looks like that the general layouting went wrong.

                        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