Results 1 to 3 of 3

Thread: QLCDNumber with transparent background?

  1. #1
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLCDNumber with transparent background?

    Hi Guys, I would like to display a QLCDWidget with no background. Eventually I will make it frameless as well (so it's just a floating number), but I haven't been able to get rid of the background yet. The background show up black, rather than being absent:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. //Set up the QLCDNumber
    6. QLCDNumber* lcdNumber = new QLCDNumber(3,0);
    7. lcdNumber->display(123);
    8. lcdNumber->setSegmentStyle(QLCDNumber::Flat);
    9.  
    10. //A palette with crazy colors to help see what's going on
    11. //Setting the background to Qt::transpatent here didn't seem to help
    12. QPalette palette = lcdNumber->palette();
    13. palette.setColor(QPalette::Active, QPalette::WindowText, Qt::green);
    14. palette.setColor(QPalette::Active, QPalette::Window, Qt::red);
    15. palette.setColor(QPalette::Inactive, QPalette::WindowText, Qt::blue);
    16. palette.setColor(QPalette::Inactive, QPalette::Window, Qt::yellow);
    17. lcdNumber->setPalette(palette);
    18.  
    19. //The following code should supress the background?
    20. //Also tried setAutoFillBackground instead of Qt::WA_OpaquePaintEvent
    21. //lcdNumber->setAutoFillBackground(true);
    22. lcdNumber->setAttribute(Qt::WA_OpaquePaintEvent, true);
    23. lcdNumber->setAttribute(Qt::WA_NoBackground, true);
    24. lcdNumber->setAttribute(Qt::WA_NoSystemBackground, true);
    25.  
    26. //Show the widget
    27. lcdNumber->show();
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    And the result is:



    Any ideas how to get rid of the background?

    Thanks!

    David

  2. #2
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLCDNumber with transparent background?

    Maybe you must open the xrender

  3. #3
    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: QLCDNumber with transparent background?

    I dont think you can achieve it directly in windows.
    You may try this -
    draw the numbers on a pixmap, create a mask from the pixmap and set it on the widget. In this way you might get only numbers displayed.

    Look for the shaped clock example in Qt demo how to use masks on widgets

Similar Threads

  1. transparent background
    By fruzzo in forum Qt Programming
    Replies: 13
    Last Post: 18th March 2008, 14:42
  2. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  3. Replies: 3
    Last Post: 8th December 2006, 18:51
  4. Transparent background Style
    By Lele in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 12:02
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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.