[Qt-interest] Dynamic painting in a QMdiArea
Pascal Francq
pfrancq at ulb.ac.be
Thu Jan 15 21:35:16 CET 2009
Very stange. qobject_cast does not work, so I have try to print the name of
the class corresponding to the QMdiSubWindow. Surprising, I have got a
'qwidget' as name. After a little search, I discover that the QMdiSubWindow
are not "real" child classes of QMdiArea ('childAt' does not work). You have
to list all sub windows and test for each (with 'geometry().contains(x,y)')
which one is the current sub-window.
I suppose it is fore this reason why QMdiArea paints under the sub-windows,
there are not childs.
On mercredi 14 janvier 2009, Scott Aron Bloom wrote:
> Also, you can try qobject_cast, which will always work across DLL
> boundries (as opposed to dynamic_cast which may not)
> Scott
>
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
> > Sent: Tuesday, January 13, 2009 3:40 PM
> > To: qt-interest at trolltech.com
> > Subject: Re: [Qt-interest] Dynamic painting in a QMdiArea
> >
> > 1. Just a wild guess.
> > Do you have Run Time Type Info enabled? At least with MSVC you can
>
> disable it
>
> > for the project. In this case dynamic_cast always returns NULL.
> > For QObject derved classes I would use QObject::inherits() instead of
> > dynamic_cast.
> >
> > To figure out which QWidget pointer you get you could use objectName()
>
> and
>
> > QMetaObject::className().
> >
> > 2. Can't give any comments on second question other that I would
>
> assume that
>
> > viewport of QMdiArea should not depend on children (QMdiSubWindow) and
>
> the
>
> > line location should be defined by Pt1 and Pt2 values in your code.
> >
> > Best regards,
> > Alex
> >
> >
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] On Behalf Of Pascal Francq
> > Sent: Tuesday, January 13, 2009 2:41 PM
> > To: qt-interest at trolltech.com
> > Subject: Re: [Qt-interest] Dynamic painting in a QMdiArea
> >
> > -----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-----
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> ------------------------------------------------------------------------
> ------
>
> > ---------------------
> > Weidlinger Associates, Inc. made the following annotations.
> >
> > "This message and any attachments are solely for the intended
>
> recipient and
>
> > may contain confidential or privileged information. If you are not the
> > intended recipient, any disclosure, copying, use, or distribution of
>
> the
>
> > information included in this message and any attachments is
>
> prohibited. If you
>
> > have received this communication in error, please notify us by reply
>
> e-mail
>
> > and immediately and permanently delete this message and any
>
> attachments. Thank
>
> > you."
> >
> > "Please consider our environment before printing this email."
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Pascal Francq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090115/24a3b771/attachment.bin
More information about the Qt-interest-old
mailing list