Results 1 to 6 of 6

Thread: QPushbutton + QLabel text color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QPushbutton + QLabel text color

    Hi,

    I want to change (1) background color for a QPushbutton (2) color of text for QPushbutton (3) background color of Qlabel (4) color of text for QLabel. I have been looking at other threads but have not been able to figure out how to best do this.
    I am posting a simple helloworld example for it. Can anyone please guide me how to modify it to do the above things?
    Thanks in advance.

    Regards,
    Ashish

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QColorGroup>
    4. #include <QLabel>
    5. #include <QWidget>
    6. #include <QHBoxLayout>
    7. #include <QObject>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication app(argc, argv);
    12. QWidget *window=new QWidget();;
    13. window->setWindowTitle("my test window");
    14.  
    15. QPushButton *hello=new QPushButton();
    16. hello->setText("Hello world!");
    17. hello->setFont(QFont("Comic Sans MS",30,QFont::Bold));
    18.  
    19. QPalette *pal= new QPalette(hello->palette());
    20. //pal->setColor(QPalette(QColor(250,0,0)));
    21. //pal->setColor(QPalette(?????-
    22. //hello->setPalette(QPalette(Qt::red));
    23.  
    24. QLabel *mylabel=new QLabel();
    25. mylabel->setFont(QFont("Times",20,QFont::Bold));
    26. mylabel->setPalette(QPalette(Qt::red));
    27. mylabel->setText("This is my Label");
    28.  
    29. myl->addWidget(hello);
    30. myl->addWidget(mylabel);
    31. window->setLayout(myl);
    32.  
    33. //mylabel->show();
    34. //hello->show();
    35. window->show();
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 2nd February 2007 at 22:13. Reason: missing [code] tags

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Setting text color on QLabel
    By Yorma in forum Newbie
    Replies: 11
    Last Post: 15th June 2006, 07:25
  3. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36
  4. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57
  5. Change the text color tab page
    By gtthang in forum Qt Programming
    Replies: 4
    Last Post: 18th February 2006, 17:38

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.