[Qt-interest] Dynamic painting in a QMdiArea
Pascal Francq
pfrancq at ulb.ac.be
Tue Jan 13 23:41:07 CET 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have solve part of my problems by creating child class of QMdiArea. I have
still two questions.
1. In the method 'mousePressEvent' I try to verify that the current mouse
position correspond to a window.
void QMyMdiArea::mousePressEvent(QMouseEvent* event)
{
QWidget* ptr(viewport()->childAt(event->x(),event->y()));
if(ptr)
cout<<"Child"<<endl;
else
{
cout<<"No Child"<<endl;
return;
}
QMdiSubWindow* ptr2=dynamic_cast<QMdiSubWindow*>(ptr);
if(ptr2)
cout<<"Sub"<<endl;
else
{
cout<<"No Sub"<<endl;
return;
}
}
When I click on a window, it shows me 'Child' but not 'Sub'. This seems
strange since all the windows I insert inherits from QMdiSubWindow (and
another class depending of the widget contained).
2. When I paint a line in the area, it is paint bellow the sub-windows. How
can I paint it above them.
void QMyMdiArea::paintEvent(QPaintEvent* event)
{
QMdiArea::paintEvent(event);
QPainter Painter(viewport());
Painter.setPen(Qt::red);
Painter.drawLine(Pt1,Pt2);
}
Thanks.
On mardi 13 janvier 2009, Pascal Francq wrote:
> Hi,
> I have develop an KDE application with a main window (inheriting
> 'KXmlGuiWindow') containing one 'QMdiArea' widget. When multiple windows
> are opened, I want to give the user the opportunity too choose two windows.
> In practice, when clicking on a button in the toolbar, the user clicks on
> one window, holds the mouse button, move to the second window, and release
> the button. This works.
> During the move, I want to draw a (red) line from the first window to the
> actual position of the mouse. The solution I use actually is to catch the
> movement of the mouse in the main KDE window, drawing a line in a QPixmap
> and calling 'updated()'. In the 'paintEvent' method of this KDE window I
> call the 'render' method of the 'QMdiArea' widget:
>
> void KInfoMng::mouseMoveEvent(QMouseEvent* event)
> {
> if(Press)
> {
> Pixmap=new QPixmap(Main->Desktop->size());
> QPainter Painter(Pixmap);
> Painter.setPen(Qt::red);
> Painter.drawLine(firstx,firsty,event->x(),event->y());
> update();
> }
> }
>
> void KInfoMng::paintEvent ( QPaintEvent * event )
> {
> if(Pixmap)
> {
> Main->Desktop->render(Pixmap); // The line was draw in Pixmap
> Pixmap=0;
> }
> else
> KXmlGuiWindow::paintEvent(event);
> }
>
> But the QMdiArea does not show anything. Does this means that I have to
> create a class inheriting from QMdiArea and to overwrite the 'paintEvent'
> method there?
>
> Thanks.
- --
Pascal Francq
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkltGIMACgkQoiZc4N+hp31J/gCfTyELurx6wJh6S1tH0ecBI3br
78wAoJ1uttzHz0S9SkwCDkeJbXMpEzyU
=YYw/
-----END PGP SIGNATURE-----
More information about the Qt-interest-old
mailing list