Results 1 to 2 of 2

Thread: how to draw background color of a label

  1. #1
    Join Date
    Mar 2011
    Location
    delhi
    Posts
    45
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation how to draw background color of a label

    hi all
    pls tell me how to draw background color of a label.(ie background color of a label is blue and text of label is white)



    thanks with regards:
    gauravg

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to draw background color of a label

    Here you go, using QPalette
    Qt Code:
    1. //main.cpp
    2. #include <QtGui>
    3. //QLabel background
    4. class MyWidget : public QLabel
    5. {
    6. public:
    7. MyWidget(QWidget* parent = 0) : QLabel(parent)
    8. {
    9. setText("QLabel");
    10. QPalette p = palette();
    11. p.setColor(QPalette::Window, Qt::blue);
    12. p.setColor(QPalette::WindowText, Qt::white);
    13. setPalette(p);
    14. }
    15. };
    16.  
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. QApplication a(argc, argv);
    21. MyWidget w;
    22. w.show();
    23. return a.exec();
    24. }
    25. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Draw line with inverted background color
    By viswanath in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2011, 04:57
  2. How to make a label be on the background?
    By Bong.Da.City in forum Newbie
    Replies: 3
    Last Post: 6th September 2010, 12:37
  3. Replies: 3
    Last Post: 18th June 2010, 14:18
  4. Display Label Color by selecting Color Picker
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 07:11
  5. Draw a line in a Label
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 23rd July 2007, 14:27

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.