[review] [PyKDE] Canvas in a widget
Jim Bublitz
jbublitz at nwinternet.com
Thu Jul 22 18:49:01 BST 2004
On Thursday 22 July 2004 01:15, Angel Lopez Muñoz wrote:
> Hello,
>
> what is the better way to use a canvas inside a widget created with
> QtDesigner??
>
> I have a frame waiting for the canvasView, but I don't know what classes,
> subclasess, parents, I have to make.
I haven't used QCanvas, but it looks like the process would be similar to
other things I've done in Qt. The frame that holds the QCanvas should be a
QCanvasView rather than something like a QFrame or QScrollView. QCanvasView
is a descendant of both of those, so all of their methods and features -
shape, shadow, scrollbars, etc - are available from QCanvasView.
If you already have a canvas to display and a main widget which will hold the
view, you would do something like:
canvasView = QCanvasView (canvas, mainWidget)
From the Qt docs, it seems that to make the canvas view interactive, you need
to subclass QCanvasView and overload some of its methods related to mouse
events. There is a simple example in the C++ Qt docs which might help (the
docs for QFrame and QScrollView might be useful too). It also appears you
need to be aware of some co-ordinate transformations. Those features are
beyond my knowledge of the subject.
To subclass QCanvasView, all you need to do is:
class CanvasView (QCanvasView):
def __init__ (self, canvas, parent): # can add more args if needed
QCanvasView.__init__ (self, canvas, parent)
<add more init code and def new or overloaded methods here>
> What I need is a place in the widget where display an image an the click in
> it to draw some points and lines. The application must know the position of
> the points in order to recalculate something and the draw another lines...
> (just to be a little descriptive)
Jim
More information about the PyQt
mailing list