greetings,
Currently i want to show 2 canvas overalapping. I mean a full canvas abd other a small providing a global eye view. I am trying it hard to imagine how to pack it on a layout.
how i can do this
greetings,
Currently i want to show 2 canvas overalapping. I mean a full canvas abd other a small providing a global eye view. I am trying it hard to imagine how to pack it on a layout.
how i can do this
You should be able to do this by making that second canvas view a child of the first one (with some help of move() and setGeometry()).
hi jacek,
there are no move() or setGeometry() defined for Q3Canvas class but are there for QWidget.There is resize() in Q3Canvas but no move for canvas. move is there for canvas Item classes.
quickNitin
Well, Q3Canvas isn't a widget and can't be displayed on its own. You're displaying the canvas in a Q3CanvasView, right? Q3CanvasView is a widget and can be moved, resized, etc. like any other widget.
Qt Code:
Q3Canvas* canvas = ... Q3CanvasView* large = ... // create the small canvas view as a child of // the large canvas view as jacek proposed Q3CanvasView* small = (canvas, large);To copy to clipboard, switch view to plain text mode
J-P Nurmi
quickNitin (7th October 2006)
thanks jpn,
this did the trick.
I have one more issue.
I want to have mouse event over this small canvasView. I want to move it to any place using mouse.There is a event handler mousePressEvent() in QWidget but how i will get to know which widgets are under mouse. How i will make this event to respond to entrance of mous just in smallCanvas.
Also such mouse events are also required for canvas items idsplayed on smallCanvas.For canvas elements using Q3Canvas::collision() i can find all canvas elements. and it is doing the task.
regards
quickNitin
Subclass Q3CanvasView and override appropriate mouse event handlers (mousePressEvent(), mouseMoveEvent() and mouseReleaseEvent()) and use that Q3CanvasView subclass as the small view. You may as well just filter the events if you don't want to subclass.
J-P Nurmi
i had tried this also but not working for moving smallCanvasview.
Qt Code:
#include <QMouseEvent> #include <Q3CanvasView> #include <QPoint> class MyCanvasView : public Q3CanvasView { Q_OBJECT public: MyCanvasView( Q3Canvas *c, QWidget *parent=0, const char *name=0, Qt::WFlags f=0 ) : Q3CanvasView( c, parent, name, f ) { dragging = 0; wt=0; } protected: { wt=childAt(e->x(),e->y()); if(wt!=0 && e->button()==Qt::LeftButton) { wxoffset=(int)(e->x()- (wt->pos).x());//!not using currently wyoffset=(int)(e->y()- (wt->pos).y()); } } { if(wt!=0) { wt->move(e->x(),e->y()); } } { if( wt!=0) { wt->move(e->x(),e->y()); wt=0; } } { Q3CanvasItemList il = canvas()->collisions( e->pos() ); for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it ) { if( (*it)->rtti() != Q3CanvasText::RTTI ) { dragging = (*it); xoffset = (int)(e->x() - dragging->x()); yoffset = (int)(e->y() - dragging->y()); return; } } } { if( dragging ) { dragging->setX( e->x() - xoffset ); dragging->setY( e->y() - yoffset ); dragging = 0; canvas()->update(); } } { if( dragging ) { dragging->setX( e->x() - xoffset ); dragging->setY( e->y() - yoffset ); canvas()->update(); } } private: QWidget *wt; Q3CanvasItem *dragging; int xoffset, yoffset; int wxoffset,wyoffset; };To copy to clipboard, switch view to plain text mode
The mouse events go directly to the small child view. Override and catch them in the child view, not in the large parent view. Alternatively you could install an event filter on the child.
J-P Nurmi
code i have posted earlier is being used for both parent and child canvasViews.
Can you give some more information on how i can catch events in child rather than on parent? A bit confused here. I will also dig through docs for this.
Maybe you should use specialized versions for the small and the large? Do you really want to be able to move canvas items around in the small view too?
J-P Nurmi
not rally but i want a rectangle there which will let me pan to other area in large canvas. and also i want to move this small canvas to any position on large canvas as per my convenience.
So the behaviour is pretty much different when comparing the small to the large view. Maybe you need to take a break in implementation and give yourself a moment to think what kind of functionalities do you actually need from those both views and how could you possibly be able to implement the required functionalities.
- when the rectangle inside the small view shall be moved (dragging anywhere inside the rect / dragging rect boundaries..)?
- when the small view itself shall be moved (always when not moving the rectangle?)
- how do you connect the views so that the large view adjusts it's world to correspond the small view's rectangle
- and so on...
Remember that a child widget is on top of it's parent. The child (the small view in your case) receives for example mouse events itself, you cannot catch them (without doing certain tricks) in the parent (the large view in your case).
J-P Nurmi
Bookmarks