Results 1 to 10 of 10

Thread: QPainter with QSystemTrayIcon issues

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default QPainter with QSystemTrayIcon issues

    Hello,

    I'm trying to make system tray icon which contains text but it fails miserably.
    Firstly the icon is made of 2 parts, one which contains text using a truetype icon fonts and another part with normal fonts.

    One issues is that the application crashes, I cannot pinpoint the method which causes the crash but I think it's the draw method. I cannot find which is the issue because if I put breakpoints into the debugger the application works if don't it returns to normal behavior partly working.

    Secondly:
    If I put one part of the text into the pixmap with a size of 22 x 22 the text appears correctly, if I put it inside a 44 x 22 (w x h) pixmap the drawing is correctly placed but it becomes blurry, you should be able to find picture into attachments.


    This is the code which shows the non-blurred number 4:
    Qt Code:
    1. QPixmap tempPixmap(22, 22);
    2. tempPixmap.fill(QColor(0,0,0,0));
    3. QPainter tempPainter(&tempPixmap);
    4. tempPainter.setPen(QColor(Qt::white));
    5. tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
    6.  
    7. QPixmap pixmap(22,22);
    8. pixmap.fill(QColor(0,0,0,0));
    9. QPainter iconPainter(&pixmap);
    10. iconPainter.drawPixmap(QRect(0, 0, 22, 22), tempPixmap);
    11. trayIcon->setIcon(QIcon(pixmap));
    To copy to clipboard, switch view to plain text mode 


    This is the code which shows the blurred version:
    Qt Code:
    1. QPixmap tempPixmap(22, 22);
    2. tempPixmap.fill(QColor(0,0,0,0));
    3. QPainter tempPainter(&tempPixmap);
    4. tempPainter.setPen(QColor(Qt::white));
    5. tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
    6.  
    7. QPixmap pixmap(44,22);
    8. pixmap.fill(QColor(0,0,0,0));
    9. QPainter iconPainter(&pixmap);
    10. iconPainter.drawPixmap(QRect(22, 0, 22, 22), tempPixmap);
    11. trayIcon->setIcon(QIcon(pixmap));
    To copy to clipboard, switch view to plain text mode 

    Can someone help me solve this issue?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter with QSystemTrayIcon issues

    Any specific reason why you are not directly painting the text into the target pixmap?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPainter with QSystemTrayIcon issues

    Quote Originally Posted by anda_skoa View Post
    Any specific reason why you are not directly painting the text into the target pixmap?

    Cheers,
    _
    Hi anda, yes, the final result should be an icon based of text + icon, but the icon itself is from a font(like font awesome icons).
    I have already tried drawing the text with the same pixmap and painter, but the end result it is the same, blurry text.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter with QSystemTrayIcon issues

    I am not sure I understand why you need a second pixmap, but have you tried passing a point instead of a target rect?

    Qt Code:
    1. iconPainter.drawPixmap(QPoint(22, 0), tempPixmap);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPainter with QSystemTrayIcon issues

    Same, text is blurry.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter with QSystemTrayIcon issues

    Did you check if the image is blurry or just when it is being displayed?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPainter with QSystemTrayIcon issues

    Quote Originally Posted by anda_skoa View Post
    Did you check if the image is blurry or just when it is being displayed?

    Cheers,
    _
    I don't think I understand properly, sorry for my late response, how can I know if the image is blurry if I am not displaying it?

  8. #8
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPainter with QSystemTrayIcon issues

    Quote Originally Posted by adutzu89 View Post
    I don't think I understand properly, sorry for my late response, how can I know if the image is blurry if I am not displaying it?
    I have tried saving the image and it's ok, the issue is when showing it in tray.

  9. #9
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPainter with QSystemTrayIcon issues

    Apparently I cannot create rectangular icons because Windows does not allow it.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter with QSystemTrayIcon issues

    That was my theory, hence asking to check if the image itself was OK (and yes, by saving it to file for example).

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 26th December 2012, 01:03
  2. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  3. Replies: 5
    Last Post: 7th September 2009, 20:57
  4. QPainter-design issues.
    By regrant in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2008, 22:24
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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
  •  
Qt is a trademark of The Qt Company.