[Qt-interest] Acquiring device context in Qt

Manish Chaturvedi manish_chaturvedi at persistent.co.in
Fri Jun 12 15:06:45 CEST 2009


Thanks Sean for a quick reply,

QWidget::setCursor() : For this case the mouse curser will assume this shape when it's over this widget, whereas I want to create this cursor on the widget. I agree with your saying that we should not set curser in onPaintEvent() but it does not seems that I have any way to create the curser on the widget.

Thanks,
Manish

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Sean Harmer
Sent: Friday, June 12, 2009 6:09 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Acquiring device context in Qt

Hi,

On Friday 12 Jun 2009 13:29:31 Manish Chaturvedi wrote:
> Hi All,
>
> I am trying to have Qt equivalent for MFC code i.e.
>
> HICON   m_hIconCursor;
>
> void MyClass::OnPaint()
> {
>       CPaintDC dc(this);
>
>       CRect rClient;
>       GetClientRect(rClient);
>
>       dc.FillSolidRect(rClient, RGB(255,255,255));
>
>       // Draw the cursor
>       dc.DrawIcon(0, 0, m_hIconCursor);
> }
>
> I've written QT equavalent OnPaint() event like this:
>
> QCursor   m_hIconCursor;
>
> void MyClass::OnPaintEvent(QPaintEvent* event)
> {
>       QPainter p(this);
>
>       QRect rect = geometry();
>
>       p.drawRect(rect);
>
> //Don't see any API of QPainter to draw the QCurser. ?? any one has idea
> how to do this.. // Draw the cursor
>
>       //dc.DrawIcon(0, 0, m_hIconCursor);
> }
>
> Let me know if it is right to use QPainter for  CPaintDC.if not, what could
> be the possible replacement of it in Qt4.3.4. I cannot see any API of
> QPainter which will allow me to paint the curser on the window. Does any
> body has any clue how to implement this? Any help will be apprietiated.
No don't do this. In Qt you should only paint on a widget in that widget's 
paintEvent() function so you would be best to overload that in your derived 
widget. However, if all you wish to do is set a custom cursor on that widget 
take a look at the docs for QWidget::setCursor().

HTH,

Sean

>
> PS: I am implementing this on Mac.
This should not matter. Qt is cross-platform.

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.




More information about the Qt-interest-old mailing list