Results 1 to 4 of 4

Thread: Problems with simple Qt Style Sheet

  1. #1
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problems with simple Qt Style Sheet

    Hello

    I have a very simple problem with the setStyleSheet() function. I need to apply a simple style to a label.
    If I make my form only with code (without using Qt Designer) I can't apply my style. An example:

    Qt Code:
    1. Form::Form(QWidget *parent) : QWidget(parent) {
    2. this->myLabel = new QLabel(this);
    3. this->myLabel->move(0,0);
    4. this->myLabel->resize(300, 100);
    5. this->setStyleSheet("#myLabel{background-color: rgb(0, 0, 255);}");
    6. }
    To copy to clipboard, switch view to plain text mode 

    It doesn't work, but if I make my form with Qt Designer it works:

    Qt Code:
    1. Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::ClientFrame) {
    2. ui->setupUi(this);
    3. this->setStyleSheet("#label {background-color: rgb(0, 0, 255);}");
    4. }
    To copy to clipboard, switch view to plain text mode 

    Someone can help me to fix the first code please??

    Thanks!!

  2. #2
    Join Date
    Oct 2006
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with simple Qt Style Sheet

    the problem is that there is no objects named "myLabel" yet.

    add this
    this->myLabel->setObjectName(QString::fromUtf8("myLabel"));

  3. The following user says thank you to Alnitak for this useful post:

    Qn00b (14th October 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with simple Qt Style Sheet

    Thank you very much for your help, I have solved my problem

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problems with simple Qt Style Sheet

    and since you set the style sheet only to your label, you don't have to specify any scope and could simply write
    Qt Code:
    1. this->setStyleSheet("background-color: rgb(0, 0, 255)");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  2. Inherited Style Sheet
    By johnmauer in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2010, 21:07
  3. Slider Style sheet
    By sijithjames in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2009, 12:43
  4. How to set Style sheet for QCalendarWidget?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 22:36
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 13:05

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.