Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with moving QGraphicsItem Fast
Forum Updated to NodeBB v4.3 + New Features

Issue with moving QGraphicsItem Fast

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 4.1k 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.
  • BlackMambaB Offline
    BlackMambaB Offline
    BlackMamba
    wrote on last edited by
    #1

    Hello,
    I do have a QGraphicsScene rendered in a QGraphicsView.
    I connected an horizontal slider position with the position of a QGraphicsItem, both added to the scene.
    The slider was added by using a QGraphicsProxyWidget.

    WHen I move the slider from left to right, the QGraphicsItem does the same.
    However, when moving the slider fast, from left to right, everything is smooth and perfect, from right to left the QGraphicsItem disappears sometimes while moving.

    Do you know why?

    I just connected this way

    @connect(slider,changePosition(int),mainwindow,SLOT(mySlotChangeItemPos(int)));@

    @mySlotChangeItemPos(int newposx){
    //
    //convert newposx to pixel value
    //
    myitem->setPos(newposx, 0);
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      "disappear" as in "never seen again", or are you talking about a flickering effect?

      1 Reply Last reply
      0
      • BlackMambaB Offline
        BlackMambaB Offline
        BlackMamba
        wrote on last edited by
        #3

        Flickering effect indeed !

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          Are the slider and item very close to each other? If so, try out if the effect is still there if you put a bit of distance between then.

          What do you actually do in the item's slot?

          Since I don't know such flickering effects (at least on typical PC hardware), I suspect the slider being used via proxy item. Can you test what happens when the events are generated some other way, e.g. by a timer, not by the slider?

          1 Reply Last reply
          0
          • BlackMambaB Offline
            BlackMambaB Offline
            BlackMamba
            wrote on last edited by
            #5

            Thanks for your help :)
            The slider and the item are indeed touching each other as I want the QGraphicsItem ( a custom line) to make the continuation of the slider's handle.
            I will try what you are proposing, however, its weird that this only appears from right to left and not from left to right doesnt it?

            1 Reply Last reply
            0
            • BlackMambaB Offline
              BlackMambaB Offline
              BlackMamba
              wrote on last edited by
              #6

              bq. What do you actually do in the item's slot?

              I dont have item's slot, I just have a slot for my mainwindow which will move this item in the scene by using setPos() according to the slider's signal.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                If all you do is calling setPos(), you shouldn't get this effect.
                What type does your QGraphicsItem have? If it's custom, are you sure the boundingRect is calculated correctly?

                1 Reply Last reply
                0
                • BlackMambaB Offline
                  BlackMambaB Offline
                  BlackMamba
                  wrote on last edited by
                  #8

                  Yes it is just what I do... I subclassed QGraphicsItem and added a drawLine in the paint method.
                  My bounding rect is calculated correctly too .. It is not updated when the item moves but I think it should not, as its a local bouding rect.
                  I cant have a look at the code right now (I am at work) but I am pretty sure its what I did.

                  But cant it come from the intersection of the item (line) with the slider as you mentionned before?

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NicuPopescu
                    wrote on last edited by
                    #9

                    what means "convert newposx to pixel value"? how do you do that?

                    1 Reply Last reply
                    0
                    • BlackMambaB Offline
                      BlackMambaB Offline
                      BlackMamba
                      wrote on last edited by
                      #10

                      I used :
                      int QStyle::sliderPositionFromValue ( int min, int max, int logicalValue, int span, bool upsideDown = false )

                      to have a pixel value from the slider value as I want the line and the slider's header to align.

                      1 Reply Last reply
                      0
                      • BlackMambaB Offline
                        BlackMambaB Offline
                        BlackMamba
                        wrote on last edited by
                        #11

                        Hello,
                        Asperamanca : after some tests, it looks like its because of the bounding rect you were right ;)
                        However, I dont know how to set it properly. I was thinking that the bounding rect doesnt need to update if you change the position.

                        I have on my line :

                        @void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
                        {
                        QPen pen(Qt::black);
                        pen.setWidth(2);

                        QBrush brush(Qt::blue);
                        painter->drawLine(0,0,0,500);
                        

                        }

                        QRectF Item::boundingRect() const
                        {
                        return QRectF(0,0,10,500);
                        }@

                        and in my window the slot:

                        @void MainWindow::changeXLinePos(int val)
                        {
                        int val2 = slid->style()->sliderPositionFromValue(0,1000,val,slid->width());
                        qDebug() << "val" << val;
                        qDebug() << "pix" << val2;
                        item->setPos(treeWidget->header()->sectionPosition(3)+val2,0);
                        }@

                        How should I set the bounding rect correctly while the item s moving?
                        Should I tale the new position as an attribute of the item, update the bounding rect after calling prepareGeometryChange?

                        Thanks for your help !

                        1 Reply Last reply
                        0
                        • BlackMambaB Offline
                          BlackMambaB Offline
                          BlackMamba
                          wrote on last edited by
                          #12

                          no idea? ;)

                          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