PDA

View Full Version : Draw lines connecting two sub-windows of QMdiArea



tom701
12th September 2010, 21:04
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:


class QMyMdiArea : public QMdiArea
{
Q_OBJECT
public:
explicit QMyMdiArea(QWidget *parent = 0);
bool eventFilter(QObject *o, QEvent *e);
protected:
void paintEvent(QPaintEvent*);
};

Implementation:


void QMyMdiArea::paintEvent(QPaintEvent* pe)
{
QMdiArea::paintEvent(pe);

QPainter p(this->viewport());
p.setPen(Qt::red);

QPointF pt1;
QPointF pt2;

p.drawLine(pt1, pt2);
}

bool QMyMdiArea::eventFilter(QObject *o, QEvent *e)
{
if(qobject_cast<QMdiSubWindow*> (o)!=0 && e->type()==QEvent::Move)
viewport()->update();
return false;
}

tbscope
12th September 2010, 21:09
You could use a transparent top widget, but that will make using the widgets underneath it pretty difficult.

I personally would try using QGraphicsView.

tom701
12th September 2010, 21:24
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!