PyQt QGraphicsView fails to setWindowIcon
I'm using sub开发者_高级运维-classed QGraphicsView's in an MDIArea I want to be able to change the icon of the window from 'within' the object, but it just seems to ignore me... no errors or warnings... it just doesn't do it.
if self.world.is_dirty:
self.setWindowIcon( QtGui.QIcon ( 'images/dirty.png' ) )
self.setWindowTitle('dirty')
else:
self.setWindowIcon( QtGui.QIcon ( 'images/clean.png' ) )
self.setWindowTitle('clean')
Using the above, the WindowTitle changes perfectly and as expected, but the icon remains stubbornly fixed as the MainWindow icon. I thought it might be stuggling with the QIcon, but I've checked the isNull() and that's false.. so not Null.
As I test, I tried the changing the icon from the MainWindow object and that works fine...
self.mdiArea.activeSubWindow().setWindowIcon(QtGui.QIcon ('images/dirty.png'))
So why is it ignoring me when i try it from the View?
Looking at the C++ docs for the windowIcon property they say that the property only makes sense if the widget is actually a window. I assume your QGraphicsView
is not actually your window?
In contrast the docs for the windowTitle property say that that property makes sense more generally for top-level widgets. That's probably the reason for the different behaviour.
精彩评论