Results 1 to 8 of 8

Thread: don't work qlineargradient for text in QLabel

  1. #1
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default don't work qlineargradient for text in QLabel

    i tried everything. in QtDesigner, gradient for QLabel works perfectly, but when i setting style sheet like this :
    "* {color: qlineargradient(spreadad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"

    dynamically in my code, i have a white text on my label
    what am i do wrong?

    here, how i do this:

    Qt Code:
    1. mpExampleLabel = new QLabel(tr("Cell text example"), this);
    2. mpExampleLabel->setFrameStyle(QFrame::Box);
    3. mpExampleLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
    4. mpExampleLabel->setStyleSheet("* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));");
    To copy to clipboard, switch view to plain text mode 
    Last edited by GreenScape; 27th July 2010 at 00:00.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: don't work qlineargradient for text in QLabel

    Looks like you are missing a closing brace in your setStyleSheet statement.

  3. #3
    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: don't work qlineargradient for text in QLabel

    You can also try to skip the "* {".

  4. #4
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: don't work qlineargradient for text in QLabel

    no, this is just example, i copied style from QtDesigner and loose brace pasting into browser

    as i said, i tried everything, without selector (i. e. without "* {" and "}"), with "QLabel" and "*".

    here, compilable example:

    #include <QApplication>
    #include <QLabel>

    int main(int argc, char *argv[])
    {
    QApplication app(argc,argv);
    QLabel mpExampleLabel("Cell text example");
    mpExampleLabel.setFrameStyle(QFrame::Box);
    mpExampleLabel.setAlignment(Qt::AlignHCenter|Qt::A lignVCenter);
    mpExampleLabel.setStyleSheet("* {color: qlineargradient(spreadad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));}");
    mpExampleLabel.show();
    return app.exec();
    }

    i always have a label with white text! (i. e. text color will be always the color of last stop of any gradient). what am i do wrong?
    Last edited by GreenScape; 27th July 2010 at 08:23.

  5. #5
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: don't work qlineargradient for text in QLabel

    i exeperimented with styles and found interesting stuff:

    when i replace
    Qt Code:
    1. color: qlineargradient(spreadad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. color: qlineargradient(spreadad, x1:0 y1:0, x2:[B]100[/B] y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
    To copy to clipboard, switch view to plain text mode 
    label's text filled with gradient starts from (0,0) to (100,0), this seems to be bug? values after x1,x2,y1,y2 means proportion of widget but not concrete width/height! x2:1 always means x2=width()*1 but not just one pixel (x==1) same gradient for background-color works perfectly(i. e. x2=width()*1).

  6. #6
    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: don't work qlineargradient for text in QLabel

    No it is not a bug. You can specify if your given coordinates should be treated absolut or streched to the actual painting area. I'd suggest also to skip the first option. Then by default it is streched to the painting area.

  7. #7
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: don't work qlineargradient for text in QLabel

    what first option? spreadad? how can i specify?

    and why absolutely the same style sheet string for background-color works relatively, but for color - absolutely?

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

    Default Re: don't work qlineargradient for text in QLabel

    Quote Originally Posted by Lykurg View Post
    No it is not a bug. You can specify if your given coordinates should be treated absolut or streched to the actual painting area. I'd suggest also to skip the first option. Then by default it is streched to the painting area.
    HOW can i specify, man!?

Similar Threads

  1. QLabel setPixmap doesnt work
    By arpspatel in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2010, 22:24
  2. How to right-justify QLabel text
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 08:55
  3. Squeeze text in QLabel
    By jiveaxe in forum Qt Programming
    Replies: 5
    Last Post: 6th September 2007, 10:45
  4. background-image on QLabel does NOT work
    By VireX in forum Newbie
    Replies: 2
    Last Post: 8th June 2007, 20:30
  5. Getting QLabel to work with WinAPI GetWindowText?
    By m.parker in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2006, 21: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.