Yao
Yao

Reputation: 127

Weird result from pyqt example: an image viewer

I'm a beginner of PyQt, and I'm reading some examples in tutorials.

When I build an image viewer from example, I find the result is weird.

https://github.com/Werkov/PyQt4/blob/master/examples/widgets/imageviewer.py

Why there is a blank area on the top left of main window? How can I remove it?

enter image description here

Upvotes: 1

Views: 1186

Answers (1)

Maciek D.
Maciek D.

Reputation: 2864

The white rectangle is the self.imageLabel object. It is white because of the self.imageLabel.setBackgroundRole(QtGui.QPalette.Base) in the main window constructor. Just comment it out and the rectangle will disappear.

The side effect of this will be that if you open a transparent image, its background will be dark gray (as the background of the rest of the window inside) and not white. If you want it white, move the line self.imageLabel.setBackgroundRole(QtGui.QPalette.Base) to the end of the open method and indent it four spaces.

Upvotes: 3

Related Questions