QGraphicsView scale not working
-
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 -
Please post the complete code (shouldn't be much), then it's easier to see where the issue is...
-
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); }
-
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.
-
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.
@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 -
@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@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.
-
@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.
@Asperamanca
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
i need increased view to edit small scenes -
@Asperamanca
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
i need increased view to edit small scenes@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.
-
@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.
@Asperamanca change of large_item on pixmap 6k x 3k not works too. large item draw lines and seconds, scenes is other rect items
-
@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.
@Asperamanca any ideas?
-
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. -
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.@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