[Qt-interest] Acquiring device context in Qt
Sean Harmer
sean.harmer at maps-technology.com
Fri Jun 12 14:39:16 CEST 2009
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.
More information about the Qt-interest-old
mailing list