Sergex
24th November 2011, 14:18
Hello,
I am trying to gain control of the scrolling of my QGraphicsViews through another widget which in this case is a QGraphicsObject.
What I have is this GraphicsObject item that can be moved only horizontally. When my GraphicsViews are zoomed-in, the item has space to move. So I am trying to control the scrolling of the views with this item, so when I move the item to one side or the other, it will be like moving the views's scroll bars horizontally to one side or the other.
I have tried doing it like this:
- First I get the value of how much the item moved in either direction and send it through a signal, I connect that to a slot in my QGraphicsView class that has this :
void myView::scrollViewSlot(int dx)
{
int position = horizontalScrollBar()->value();
position += dx;
horizontalScrollBar()->setValue(position);
}
This is so that wherever the value of the horizontal scrollbar was, in this case I add to that value how much I would like to scroll and set the value of the horizontalScrollbar of the view, so it should move (scroll) the views. I understand that the value to add to the current horizontalScrollBar value must be well calculated by making tests no matter what the value is the views never scroll. I have made sure that the singal/slots are well connected and when I move the item, the slot gets reached with a value but the views don't move.
What am I missing to make this work properly?
Thanks.
I am trying to gain control of the scrolling of my QGraphicsViews through another widget which in this case is a QGraphicsObject.
What I have is this GraphicsObject item that can be moved only horizontally. When my GraphicsViews are zoomed-in, the item has space to move. So I am trying to control the scrolling of the views with this item, so when I move the item to one side or the other, it will be like moving the views's scroll bars horizontally to one side or the other.
I have tried doing it like this:
- First I get the value of how much the item moved in either direction and send it through a signal, I connect that to a slot in my QGraphicsView class that has this :
void myView::scrollViewSlot(int dx)
{
int position = horizontalScrollBar()->value();
position += dx;
horizontalScrollBar()->setValue(position);
}
This is so that wherever the value of the horizontal scrollbar was, in this case I add to that value how much I would like to scroll and set the value of the horizontalScrollbar of the view, so it should move (scroll) the views. I understand that the value to add to the current horizontalScrollBar value must be well calculated by making tests no matter what the value is the views never scroll. I have made sure that the singal/slots are well connected and when I move the item, the slot gets reached with a value but the views don't move.
What am I missing to make this work properly?
Thanks.