Results 1 to 5 of 5

Thread: Draw text in the same device context with win32

  1. #1
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Draw text in the same device context with win32

    Hi I have just started to use QT and I want gradually to change my win32 screensaver to use QT functions and be finally able to work on Mac.

    In my win32 code, I use the windows desktop device context to draw bitmaps. The bitmaps are created by a textOut function (the win32 textout)

    Can some of the graphics be drawn by QT and some other graphics by my win32 API functions? Is there a source example that by having the hDC (device context) I can use QPainter to draw things on the same window?

    Thanks
    Mike
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Moonphases screensaver

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw text in the same device context with win32

    Yes, although this is not trivial and only one way (you can use GDI calls to draw on Qt widgets but not QPainter to draw on non-Qt devices). Why can't you make a leap from winapi to Qt in one go?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Draw text in the same device context with win32

    What you propose is the oposite from what I need. I need to draw with QT on the desktop where other API calls also draw.
    As you know a screensaver consists of the drawing on the desktop and the configuration dialog.
    From your reply I think it would be more easy to start transfering to QT the dialog of the screensaver and leave for a later step the desktop drawing of the screensaver?

    I am developing with visual studio 2005.
    To create a dialog widget, do I need first to initiate a QApplication object?
    How can I initiate it since all the QT examples need argc and argv
    QApplication ( int & argc, char ** argv )
    This main() is a "dos" version. The screensaver has a winmain function without the argc and argv arguments.
    (Confused)

    Is there an example of win32 and QT leaving together in the same windows application?
    Thank you very much
    Michael
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Moonphases screensaver

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw text in the same device context with win32

    Quote Originally Posted by mioan View Post
    What you propose is the oposite from what I need. I need to draw with QT on the desktop where other API calls also draw.
    You can try opening a painter on QDesktopWidget.

    From your reply I think it would be more easy to start transfering to QT the dialog of the screensaver and leave for a later step the desktop drawing of the screensaver?
    Configuration dialog is trivial once you have all the infrastructure running so I'd suggest going for the screen saver first.

    To create a dialog widget, do I need first to initiate a QApplication object?
    Yes.

    This main() is a "dos" version.
    No, it's not. World doesn't end on Windows, neither it begins there. main() is a classic C interface and winmain() is an artificial function that is called from the real main provided by msvc.

    The screensaver has a winmain function without the argc and argv arguments.
    (Confused)
    So make it have a main() and not winmain, that's not a problem.

    Is there an example of win32 and QT leaving together in the same windows application?
    Each Qt application running on Windows is a "win32" application.

    Stop thinking in terms of Visual Studio and start thinking in terms of programming. Start with main(), create an application object there, do everything you want related to pure winapi calls if you want and call QApplication::exec(). Just remember the latter is an event loop that will block until your application exits.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw text in the same device context with win32

    If you are concerned about the whole desktop, you can think of your application occupying the whole screen, and paint whatever u like. Simple.
    You can use showFullScreen for that.

    Also you can move your widget on the desktop while painting is done inside the widget. This is second approach.

    Why do you think any of them wont work ?
    Hint : In a screensaver, the desktop is your playground

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. How to draw vertical text via QTextEdit
    By nifei in forum Qt Programming
    Replies: 8
    Last Post: 1st October 2010, 17:10
  3. Replies: 0
    Last Post: 10th April 2009, 15:28
  4. QLineEdit, draw only text
    By Radagast in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2009, 11:15
  5. How to draw columns text in QTextDocument?
    By nifei in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2009, 02:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.