Results 1 to 2 of 2

Thread: How is it easier to change font properties?

  1. #1
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How is it easier to change font properties?

    Hi,
    I'm trying to find the easiest way to change font parameters for different text in widgets. Using html code would be fine, but it seems to not work everywhere for me... For example to write a string in italic in the ListWidget I do the following:

    Qt Code:
    1. QListWidgetItem *item = new QListWidgetItem("Text...");
    2. QFont *font = new QFont;
    3. font->setItalic(true);
    4. item->setFont(*font);
    5. listWidget->insertItem(0,item);
    To copy to clipboard, switch view to plain text mode 

    ...which is a quite long way. How to do it simpler?
    If I write "<i>Text...</i>" instead of "Text..." this doesn't work.

    Thanks!!
    Last edited by jpn; 11th July 2008 at 08:15. Reason: missing [code] tags

  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: How is it easier to change font properties?

    Quote Originally Posted by alex chpenst View Post
    QFont *font = new QFont;
    ...
    item->setFont(*font);
    I hope you know that, if you won't delete that QFont object, you will get a memory leak. It's better to create that QFont on the stack in this case.

    Quote Originally Posted by alex chpenst View Post
    ...which is a quite long way. How to do it simpler?
    Write a createItalicListWidgetItemOrWhatever() function or subclass QListWidgetItem to make it understand rich text. Depending on what you want to achieve, you can also try style sheets.

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

    alex chpenst (12th July 2008)

Similar Threads

  1. How to prevent table header from font change.
    By kenny_isles in forum Qt Tools
    Replies: 1
    Last Post: 14th February 2007, 19:01
  2. How do I change the font color in QTextBrowser?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2006, 12:08
  3. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16
  4. Change Font Color of Label and CheckBox
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 15th June 2006, 10:24
  5. Change font in QPainter::drawText
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 19th May 2006, 16:21

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.