Absurd
8th September 2017, 11:35
Hey there.
I am new to this forum and to Qt Programming in general.
Making my first step through PyQt (yep, I am Python enthusiastic, I hope there's room for PyQt here as well).
I am trying to write a small qt app, but having some difficulty to set up a scroll bar the way I want (all the way to the top).
I have sub-classed QGraphicsView, to which I added a Scene with some items on it.
The items do not all fit into the QGraphicsView so a vertical scroll bar appears.
But the scroll bar is not scrolled all the way up, but rather it is scrolled exactly in the middle.
So, I tried doing that from (Python's) initializer:
self.verticalScrollBar().setValue(self.verticalScr ollBar().minimum())
but this seems to have no effect!
Curiously, when I do it like that:
# in initializer:
QTimer.singleShot(0, self.test)
def test(self):
self.verticalScrollBar().setValue(self.verticalScr ollBar().minimum())
it does seem to work, and the vertical scroll bar is set to the top!
I understand that the difference between running something from the initializer and with QTimer.singleShot(0, self.test) is that self.test will be called after the event handler is running.
So the question is: why doesn't that working when I set the scroll bar value before the event handler is running, but does work when setting the value after the event handler is running?
Any help would be greatly appreciated.
Thanks!
I am new to this forum and to Qt Programming in general.
Making my first step through PyQt (yep, I am Python enthusiastic, I hope there's room for PyQt here as well).
I am trying to write a small qt app, but having some difficulty to set up a scroll bar the way I want (all the way to the top).
I have sub-classed QGraphicsView, to which I added a Scene with some items on it.
The items do not all fit into the QGraphicsView so a vertical scroll bar appears.
But the scroll bar is not scrolled all the way up, but rather it is scrolled exactly in the middle.
So, I tried doing that from (Python's) initializer:
self.verticalScrollBar().setValue(self.verticalScr ollBar().minimum())
but this seems to have no effect!
Curiously, when I do it like that:
# in initializer:
QTimer.singleShot(0, self.test)
def test(self):
self.verticalScrollBar().setValue(self.verticalScr ollBar().minimum())
it does seem to work, and the vertical scroll bar is set to the top!
I understand that the difference between running something from the initializer and with QTimer.singleShot(0, self.test) is that self.test will be called after the event handler is running.
So the question is: why doesn't that working when I set the scroll bar value before the event handler is running, but does work when setting the value after the event handler is running?
Any help would be greatly appreciated.
Thanks!