Results 1 to 12 of 12

Thread: overlapping canvases

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default overlapping canvases

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: overlapping canvases

    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()).

  3. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping canvases

    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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: overlapping canvases

    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:
    1. Q3Canvas* canvas = ...
    2. Q3CanvasView* large = ...
    3. // create the small canvas view as a child of
    4. // the large canvas view as jacek proposed
    5. Q3CanvasView* small = (canvas, large);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    quickNitin (7th October 2006)

  6. #5
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping canvases

    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

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: overlapping canvases

    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

  8. #7
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping canvases

    i had tried this also but not working for moving smallCanvasview.
    Qt Code:
    1. #include <QMouseEvent>
    2. #include <Q3CanvasView>
    3. #include <QPoint>
    4. class MyCanvasView : public Q3CanvasView
    5. {
    6. Q_OBJECT
    7. public:
    8. MyCanvasView( Q3Canvas *c, QWidget *parent=0, const char *name=0, Qt::WFlags f=0 ) : Q3CanvasView( c, parent, name, f )
    9. {
    10. dragging = 0;
    11. wt=0;
    12. }
    13.  
    14. protected:
    15.  
    16. void mousePressEvent(QMouseEvent *e)
    17. {
    18. wt=childAt(e->x(),e->y());
    19. if(wt!=0 && e->button()==Qt::LeftButton)
    20. {
    21. wxoffset=(int)(e->x()- (wt->pos).x());//!not using currently
    22. wyoffset=(int)(e->y()- (wt->pos).y());
    23.  
    24.  
    25. }
    26. }
    27.  
    28. void mouseMoveEvent(QMouseEvent *e)
    29. {
    30. if(wt!=0)
    31. {
    32. wt->move(e->x(),e->y());
    33. }
    34. }
    35.  
    36. void mouseReleaseEvent(QMouseEvent *e)
    37. {
    38. if( wt!=0)
    39. {
    40. wt->move(e->x(),e->y());
    41. wt=0;
    42. }
    43. }
    44.  
    45.  
    46. void contentsMousePressEvent( QMouseEvent *e )
    47. {
    48. Q3CanvasItemList il = canvas()->collisions( e->pos() );
    49. for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it )
    50. {
    51. if( (*it)->rtti() != Q3CanvasText::RTTI )
    52. {
    53. dragging = (*it);
    54.  
    55. xoffset = (int)(e->x() - dragging->x());
    56. yoffset = (int)(e->y() - dragging->y());
    57.  
    58. return;
    59. }
    60. }
    61. }
    62.  
    63. void contentsMouseReleaseEvent( QMouseEvent *e )
    64. {
    65. if( dragging )
    66. {
    67. dragging->setX( e->x() - xoffset );
    68. dragging->setY( e->y() - yoffset );
    69.  
    70. dragging = 0;
    71.  
    72. canvas()->update();
    73. }
    74. }
    75.  
    76. void contentsMouseMoveEvent( QMouseEvent *e )
    77. {
    78. if( dragging )
    79. {
    80. dragging->setX( e->x() - xoffset );
    81. dragging->setY( e->y() - yoffset );
    82.  
    83. canvas()->update();
    84. }
    85. }
    86.  
    87. private:
    88.  
    89.  
    90. QWidget *wt;
    91. Q3CanvasItem *dragging;
    92. int xoffset, yoffset;
    93. int wxoffset,wyoffset;
    94. };
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: overlapping canvases

    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

  10. #9
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping canvases

    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.

  11. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: overlapping canvases

    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

  12. #11
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping canvases

    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.

  13. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: overlapping canvases

    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

Similar Threads

  1. QTableWidget with overlapping cells (span)
    By rhi in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 18:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.