QGraphicsView showEvent not working.
-
-
wrote on 28 Jun 2021, 06:06 last edited by jeremy_k
@mrjj said in QGraphicsView showEvent not working.:
@jeremy_k
ok. That's actually much like c++ except you don't have to see, write or care about it :)Python is great like that. It pushes you to do it yourself, or use tooling to solve problems. The tooling is unable to give definitive answers because so many typos result in legal code with different behavior. I'm ready to go back to C++.
-
@mrjj said in QGraphicsView showEvent not working.:
@jeremy_k
ok. That's actually much like c++ except you don't have to see, write or care about it :)Python is great like that. It pushes you to do it yourself, or use tooling to solve problems. The tooling is unable to give definitive answers because so many typos result in legal code with different behavior. I'm ready to go back to C++.
@jeremy_k
Well, i had very little experience with it. back when it was kinda new, i did fool around with it a bit and
then mail the code to home. At home, the program suddenly didn't run as expected and i realized how deadly spaces can be and that was the end of my excitement over the language.But its very popular. So I guess it does works well for some people.
-
wrote on 28 Jun 2021, 06:20 last edited by
@jeremy_k sorry, what did you mean, I do not understand well.
-
@jeremy_k sorry, what did you mean, I do not understand well.
-
@jeremy_k sorry, what did you mean, I do not understand well.
class PhotoViewer(QtWidgets.QGraphicsView): tool_lock = 'mouse' def __init__(self, parent): ... def showEvent(self, event): super().showEvent(event) print("Test") self.showEventHelper() def showEventHelper(self): self.fitInView()
-
class PhotoViewer(QtWidgets.QGraphicsView): tool_lock = 'mouse' def __init__(self, parent): ... def showEvent(self, event): super().showEvent(event) print("Test") self.showEventHelper() def showEventHelper(self): self.fitInView()
wrote on 28 Jun 2021, 06:24 last edited by@jsulm oh, sorry I am not notice that, but this is not a problem, it way my typo when I copy from my vscode, in my vscode is
class PhotoViewer(QtWidgets.QGraphicsView): tool_lock = 'mouse' def __init__(self, parent): super(PhotoViewer, self).__init__(parent) ... def showEvent(self, event): super().showEvent(event) print("Test") self.showEventHelper() def showEventHelper(self): self.fitInView()
and the problem still not solve.
-
class PhotoViewer(QtWidgets.QGraphicsView): tool_lock = 'mouse' def __init__(self, parent): ... def showEvent(self, event): super().showEvent(event) print("Test") self.showEventHelper() def showEventHelper(self): self.fitInView()
wrote on 28 Jun 2021, 06:25 last edited by darrenleeleelee1@jsulm sorry it is my mistake, the print("Test") still not be run.Even when I correct the scope of functions.
-
Hi,
There's an issue with your init function. The first parameter shall be a scene, the second is the parent.
See the class documentation
-
Hi,
There's an issue with your init function. The first parameter shall be a scene, the second is the parent.
See the class documentation
wrote on 28 Jun 2021, 23:03 last edited by@SGaist I wonder if that documentation is malformatted due to Python not supporting function overloading. The highlighted line indicates two arguments for the constructor. Inset below that appears to be a second constructor version that only accepts an optional QWidget parent. The two sentences at the end initially attracted my attention.
-
@SGaist I wonder if that documentation is malformatted due to Python not supporting function overloading. The highlighted line indicates two arguments for the constructor. Inset below that appears to be a second constructor version that only accepts an optional QWidget parent. The two sentences at the end initially attracted my attention.
-
@jeremy_k
Are you just commenting on the confusion, or have you changed your code? Whatever the case you will need to set the view's scene, either through the constructor or viasetScene()
.wrote on 29 Jun 2021, 07:19 last edited by@JonB It's not my code.
I'm not convinced that misuse of the constructor which doesn't throw an exception or lead to program termination will cause a correctly implemented showEvent() to be ignored. A view without a scene is blank, but still a valid and showable QWidget.
import PyQt5.QtWidgets as QtWidgets class View(QtWidgets.QGraphicsView): def showEvent(self, event): print("showEvent") super().showEvent(event) app = QtWidgets.QApplication([]) view = View() view.show()
~:$ python test.py showEvent
-
@JonB It's not my code.
I'm not convinced that misuse of the constructor which doesn't throw an exception or lead to program termination will cause a correctly implemented showEvent() to be ignored. A view without a scene is blank, but still a valid and showable QWidget.
import PyQt5.QtWidgets as QtWidgets class View(QtWidgets.QGraphicsView): def showEvent(self, event): print("showEvent") super().showEvent(event) app = QtWidgets.QApplication([]) view = View() view.show()
~:$ python test.py showEvent
wrote on 29 Jun 2021, 07:27 last edited by JonB@jeremy_k said in QGraphicsView showEvent not working.:
A view without a scene is blank, but still a valid and showable QWidget.
I was not aware of this. Your code shows
showEvent
being printed. Originally you said "Test never be printed out". So what is the situation? -
@jeremy_k said in QGraphicsView showEvent not working.:
A view without a scene is blank, but still a valid and showable QWidget.
I was not aware of this. Your code shows
showEvent
being printed. Originally you said "Test never be printed out". So what is the situation?wrote on 29 Jun 2021, 07:32 last edited by jeremy_k@JonB said in QGraphicsView showEvent not working.:
@jeremy_k said in QGraphicsView showEvent not working.:
A view without a scene is blank, but still a valid and showable QWidget.
I was not aware of this. Your code shows
showEvent
being printed. Originally you said "Test never be printed out".I'm not the OP.
-
@JonB said in QGraphicsView showEvent not working.:
@jeremy_k said in QGraphicsView showEvent not working.:
A view without a scene is blank, but still a valid and showable QWidget.
I was not aware of this. Your code shows
showEvent
being printed. Originally you said "Test never be printed out".I'm not the OP.
wrote on 29 Jun 2021, 07:35 last edited by JonB@jeremy_k
Oh, LOL, sorry about that! Well @darrenleeleelee1, what is the difference between your case where you sayshowEvent()
is not hit and @jeremy_k's case where he shows it being hit? Or has this been solved and I am not understanding?! -
wrote on 29 Jun 2021, 11:30 last edited by
thanks guy I get my goal by the other way
17/23