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. QGraphicsView scale not working
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView scale not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 926 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.
  • D Offline
    D Offline
    Daniil S.
    wrote on last edited by Daniil S.
    #1

    Hello everyone, no one answers the same question from another person, I'll try it too. I have a reimplement QGraphicsView and on it an QGraphicsRectItem 15000x160, mouse wheel event is overridden for scaling and
    scale (factor, 1.0)
    doesn't work. I need scale only horizontally, QGraphicsRect item flag ItemIgnoresTransformations = false

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

      Please post the complete code (shouldn't be much), then it's easier to see where the issue is...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Daniil S.
        wrote on last edited by Daniil S.
        #3

        constructor of qgraphicsview

        setScene(new QGraphicsScene(this));
        
        large_item->setRect(15000,160);
        
        scene()->addItem(large_item);
        scene()->setSceneRect(large_item->rect());
        
        setFixedHeight(large_item->rect().height());
        fitInView(sceneRect());
        
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setMouseTracking(true);
        

        wheel event this view

        if (event->modifiers().testFlag(Qt::ControlModifier)) {
        
            QRectF view_rect =  mapToScene(this->viewport()->rect()).boundingRect();
            current_scale_ = view_rect.width() / scene()->width();
            current_scale_ = current_scale_ + (event->angleDelta().y() > 0 ? 0.25 : current_scale_ < 0.25 ? 0 : -0.25);
        
            if (current_scale_ <= 1.0)
              current_scale_ = 1.0;
            if (current_scale_ >= 3.0)
              current_scale_ = 3.0;
        
           resetTransform();
            
           scale(current_scale_, 1.0);
            
           centerOn(mapToScene(QCursor::pos())); 
        } else {
           QGraphicsView::wheelEvent(event);
        }
        
        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          Ok, so what actually happens?

          • Do you enter the correct wheel event branch?
          • Is current_scale_ a reasonable value when you set it on the GraphicsView?

          What do you expect to see, anyway? You start out with a rectangle that should fill your view, and it can only get bigger horizontally. I would expect you to see a big bar, and no visual change when you try scaling via wheel event.

          D 1 Reply Last reply
          0
          • A Asperamanca

            Ok, so what actually happens?

            • Do you enter the correct wheel event branch?
            • Is current_scale_ a reasonable value when you set it on the GraphicsView?

            What do you expect to see, anyway? You start out with a rectangle that should fill your view, and it can only get bigger horizontally. I would expect you to see a big bar, and no visual change when you try scaling via wheel event.

            D Offline
            D Offline
            Daniil S.
            wrote on last edited by Daniil S.
            #5

            @Asperamanca curent_scale initialize as 1.0, wheel event works correctly, if angleDelta > 0 then scale (1.25, 1.0) and its not work.
            I am doing something like a timeline, like in video editors, which can be scaled horizontally to increase the display

            A 1 Reply Last reply
            0
            • D Daniil S.

              @Asperamanca curent_scale initialize as 1.0, wheel event works correctly, if angleDelta > 0 then scale (1.25, 1.0) and its not work.
              I am doing something like a timeline, like in video editors, which can be scaled horizontally to increase the display

              A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              @Daniil-S
              Again, what do you expect to see?
              You have a featureless rectangle that is much wider than the view (I suppose). By calling fitInView initially, you get a horizontal scale value probably much smaller than 1. Then you scale in the wheel event, but you delimit the scale value from 1 to 3.

              Anything that happens will happen outside of the screen. Try allowing much smaller scale values and see what happens.

              D 1 Reply Last reply
              2
              • A Asperamanca

                @Daniil-S
                Again, what do you expect to see?
                You have a featureless rectangle that is much wider than the view (I suppose). By calling fitInView initially, you get a horizontal scale value probably much smaller than 1. Then you scale in the wheel event, but you delimit the scale value from 1 to 3.

                Anything that happens will happen outside of the screen. Try allowing much smaller scale values and see what happens.

                D Offline
                D Offline
                Daniil S.
                wrote on last edited by Daniil S.
                #7

                @Asperamanca 1.png my timeline looks like this, but I want to scale it, I checked everything, 1.25, 1.0 values are passed to the scale method and it does not work. I expect to see somthing like this 1.png
                i need increased view to edit small scenes

                A 1 Reply Last reply
                0
                • D Daniil S.

                  @Asperamanca 1.png my timeline looks like this, but I want to scale it, I checked everything, 1.25, 1.0 values are passed to the scale method and it does not work. I expect to see somthing like this 1.png
                  i need increased view to edit small scenes

                  A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  @Daniil-S
                  Ok, now I see. Does large_item paint everything itself, or is it composed of other items?

                  For testing, please replace large_item with a large QGraphicsPixmapItem and see how the behavior is there.

                  D 2 Replies Last reply
                  0
                  • A Asperamanca

                    @Daniil-S
                    Ok, now I see. Does large_item paint everything itself, or is it composed of other items?

                    For testing, please replace large_item with a large QGraphicsPixmapItem and see how the behavior is there.

                    D Offline
                    D Offline
                    Daniil S.
                    wrote on last edited by Daniil S.
                    #9

                    @Asperamanca change of large_item on pixmap 6k x 3k not works too. large item draw lines and seconds, scenes is other rect items

                    1 Reply Last reply
                    0
                    • A Asperamanca

                      @Daniil-S
                      Ok, now I see. Does large_item paint everything itself, or is it composed of other items?

                      For testing, please replace large_item with a large QGraphicsPixmapItem and see how the behavior is there.

                      D Offline
                      D Offline
                      Daniil S.
                      wrote on last edited by
                      #10

                      @Asperamanca any ideas?

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

                        It's really hard to help without a little more specific information.

                        If you say "not works too" about the pixmap, what does that mean? The pixmap does not scale at all? The pixmap does not scale how you would expect it?
                        Is there any other code (that you didn't post) which might affect the scaling of the view?
                        Have you looked at the 40000 chips example? They use view scaling.

                        D 1 Reply Last reply
                        1
                        • A Asperamanca

                          It's really hard to help without a little more specific information.

                          If you say "not works too" about the pixmap, what does that mean? The pixmap does not scale at all? The pixmap does not scale how you would expect it?
                          Is there any other code (that you didn't post) which might affect the scaling of the view?
                          Have you looked at the 40000 chips example? They use view scaling.

                          D Offline
                          D Offline
                          Daniil S.
                          wrote on last edited by
                          #12

                          @Asperamanca yes i saw 40k chips. If i change all items that has big sizes - it works , if i change background with lines on QRect(0,0,500,500) and remove all scenes items that not contains on background

                          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