views:

35

answers:

1

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?

A: 

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.

Troubadour
The QGraphicsView isn't a "top-level" widget as I understand them.. since it has a parent QMdiSubWindow... it just seems a bit inconsistent.setWindowTitle() works on both the QGV and its parent()setWindowIcon() only works on the parent()But at least it works now... thanks :)
Dan B
@Dan B: Yes, that's still a bit odd then. I'd suggest it's more a bug with the title property than the icon!
Troubadour