Results 1 to 3 of 3

Thread: Draw lines connecting two sub-windows of QMdiArea

  1. #1
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Draw lines connecting two sub-windows of QMdiArea

    Dear All,
    I need GUI to show correspondences between points from two images (a computer vision task). But I have problem drawing lines to connect these corresponding points. The QMdiArea has QScrollArea as sub-windows. The problem is: part of the lines drawn is always underneath the QScrollArea (the sub-window). Please see the attached figure, and the code to draw is shown below. How can I draw the lines on top of the sub-windows of QMdiArea? Thank you for help!

    Header:

    Qt Code:
    1. class QMyMdiArea : public QMdiArea
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit QMyMdiArea(QWidget *parent = 0);
    6. bool eventFilter(QObject *o, QEvent *e);
    7. protected:
    8. void paintEvent(QPaintEvent*);
    9. };
    To copy to clipboard, switch view to plain text mode 

    Implementation:

    Qt Code:
    1. void QMyMdiArea::paintEvent(QPaintEvent* pe)
    2. {
    3. QMdiArea::paintEvent(pe);
    4.  
    5. QPainter p(this->viewport());
    6. p.setPen(Qt::red);
    7.  
    8. QPointF pt1;
    9. QPointF pt2;
    10.  
    11. p.drawLine(pt1, pt2);
    12. }
    13.  
    14. bool QMyMdiArea::eventFilter(QObject *o, QEvent *e)
    15. {
    16. if(qobject_cast<QMdiSubWindow*> (o)!=0 && e->type()==QEvent::Move)
    17. viewport()->update();
    18. return false;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Draw lines connecting two sub-windows of QMdiArea

    You could use a transparent top widget, but that will make using the widgets underneath it pretty difficult.

    I personally would try using QGraphicsView.

  3. The following user says thank you to tbscope for this useful post:

    tom701 (12th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Draw lines connecting two sub-windows of QMdiArea

    Thank you very much for the suggestion! I tried to get the "Handle" to the desktop, and then draw on it, but it seems impossible in MS Widnows using QT. I am going to play with QGraphicsView which seems to be the only solution. Thanks a lot for help!

Similar Threads

  1. Draw lines in a QGridLayout
    By Eos Pengwern in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 01:27
  2. connecting lines?
    By konvex in forum Qt Programming
    Replies: 8
    Last Post: 16th December 2008, 09:00
  3. How to draw some points and lines?
    By luffy27 in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 16:47
  4. How to draw lines with the right width?
    By albanelporto in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2006, 11:51

Tags for this Thread

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.