Results 1 to 12 of 12

Thread: setText and html

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default setText and html

    Hello, if i have a QLabel i can do this:

    ui.label->setText ( tr ( "<b><font color=red>Label</font></b>" ) );

    and i see "Label" in red bold

    instead of, if i have a QCheckBox i can't do this:

    ui.checkBox->setText ( tr ( "<b><font color=red>Check box</font></b>" ) );

    or better, i get no errors but it shows on the GUI

    <b><font color=red>Check box</font></b>

    and not "Check box" in red bold.
    Any Ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    Checkboxes don't understand rich text. Set the font using QCheckBox::setFont() or use a style sheet.

  3. #3
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setText and html

    this way is good for me:
    Qt Code:
    1. QFont font(QFont::Bold);
    2. ui.checkBox->setFont (font);
    3. ui.checkBox->setText ( tr ( "text" ) );
    To copy to clipboard, switch view to plain text mode 

    but what shuld i do to set the red color?

    thx

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    Use QPalette:
    Qt Code:
    1. QPalette p( ui.checkBox->palette() );
    2. ...
    3. ui.checkBox->setPalette( p );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setText and html

    i have to get the palette and change the color?
    im not to skilled with this stuff...can you show me how to do it?
    thx

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    I gave you 66% of the necessary code. See QPalette::ColorGroup.

  7. #7
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setText and html

    I tried in this way

    Qt Code:
    1. QPalette p( checkbox->palette() );
    2.  
    3. QColor c(Qt::red);
    4. p.setColor(QPalette::Text,c);
    5.  
    6. checkbox->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    but nothing...why doesn't it work?
    thx

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    Quote Originally Posted by mattia View Post
    why doesn't it work?
    Look here:


    You should change the QPalette::WindowText colour.

  9. #9
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setText and html

    Hi, with this code i correctly set bold-red text on checkbox but i have some problem to show it using gnome, i just get a bold-black text.
    Any hint?
    Qt Code:
    1. void setRichTextOnCheckBox ( QCheckBox * checkbox , QString message )
    2. {
    3. QFont font ("" , 9 , QFont::Bold );
    4. checkbox->setFont( font );
    5.  
    6.  
    7. QPalette p ( checkbox->palette() );
    8. QColor c(Qt::red);
    9. p.setColor(QPalette::WindowText,c);
    10. checkbox->setPalette(p);
    11.  
    12. checkbox->setText( message );
    13. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    Can you see the red text if you start your application with -style plastique switch? Do you use any stylesheets?

  11. #11
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setText and html

    what the argument

    -style plastique

    should do?
    thx

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setText and html

    If will change the default style to Plastique.

Similar Threads

  1. QTextEdit setText override?
    By ksierens in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2006, 17:59

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.