[PyKDE] QCanvasView C++/PyQt differences?
phil at river-bank.demon.co.uk
Fri Jun 29 00:36:18 BST 2001
Lawrence Chai wrote:
> I was working with PyQt and was having trouble getting the QCanvasView
> widget to resize properly. I thought it was a problem with the widget,
> so I wrote a small C++ program to demonstrate it to Trolltech. However,
> when I ran the C++ version, everything seemed to work fine. I was
> wondering what possible differences there might be and if there was
> anything I could do to get the same behavior in the PyQt version as in
> the C++ version. I've attached a small python script as well as the
> equivalent C++ source code. When running, you'll notice that in the C++
> version, the QCanvasWidget is the same height as the QLabel and the
> QLineEdit, whereas in the python version, the QCanvas widget is much
> taller. Any insight into this would be much appreciated. Thanks!
Compare the Python call to the ColorSwatchCanvasView ctor...
> class ColorSwatch(QWidget):
> def __init__(self, parent):
> QWidget.__init__(self, parent)
> self.colorSwatchCanvasView = ColorSwatchCanvasView(parent)
> self.hSize = self.width() - 4
> self.vSize = self.height() - 4
> self.canvas = QCanvas(self.hSize, self.vSize)
> self.pixmap = QPixmap(self.hSize, self.vSize)
...with the C++ version...
> ColorSwatch::ColorSwatch(QWidget * parent) : QWidget(parent)
> colorSwatchCanvasView = new ColorSwatchCanvasView(this);
> hSize = width() - 4;
> vSize = height() - 4;
> canvas = new QCanvas(hSize, vSize);
> pixmap = new QPixmap(hSize, vSize);
In other words, use "self" instead of "parent".
More information about the PyQt