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] Flickering rectangle during resizing
QtWS25 Last Chance

[Solved] Flickering rectangle during resizing

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.7k 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.
  • I Offline
    I Offline
    ihaveajob
    wrote on last edited by
    #1

    Hello, I'm pretty new to Qt Quick, so hopefully this will be obvious to someone here. I'm trying to have one big rectangle anchored to the top-left of the main view, and to a second, smaller rectangle (named "cross") on the opposite (bottom right) corner. The smaller rectangle can be dragged with the mouse. It does work, sort of, with 2 problems:

    • The resizing is very flickering and it shows a ghost copy of the same rectangle
    • The resizing happens at about half the speed with which I move the mouse

    Here's my code, simplified:
    @import QtQuick 1.0

    Rectangle {
    width: 360
    height: 360

    Rectangle {
        id : cross
        x: 274
        y: 265
        width: 44 ; height: 44 ; z: 1
        color: "blue"
        MouseArea {
            anchors.fill: parent
            onPositionChanged: {
                console.log("\ncross: " + cross.x + ", " + cross.y)
                console.log("mouse: " + mouseX + ", " + mouseY)
                cross.x = mouseX
                cross.y = mouseY
            }
        }
    }
    
    Rectangle {
        id: q1
        color: "grey"
        anchors.left: parent.left
        anchors.right: cross.horizontalCenter
        anchors.top: parent.top
        anchors.bottom: cross.verticalCenter
        Text { text: "centered text" ; anchors.centerIn: parent }
    }
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      On lines 18 and 19 use:

      @
      cross.x += mouseX
      cross.y += mouseY
      @

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ihaveajob
        wrote on last edited by
        #3

        Thanks mlong! Of course the mouse coordinates are relative to the MouseArea, no the whole screen... This is interesting. I'm guessing the flickering was caused by the mouseX property taking the values of Rectangle "cross" and its parent, alternatively. Is that correct?

        Also, I'm making the Rectangle's center follow the mouse with this:
        @ cross.x += mouseX - cross.width/2
        cross.y += mouseY - cross.height/2
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Great! Glad it's working.

          Please be sure and edit your the thread's title and add [Solved] at the beginning.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          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