Results 1 to 2 of 2

Thread: How to set several fonts for one Qstandarditem (different fonts for parts of text)

  1. #1
    Join Date
    Feb 2021
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question How to set several fonts for one Qstandarditem (different fonts for parts of text)

    Hi, i use PyQT5, i have a QStandardItemModel in which i appendRows, which consist of QStandardItems.
    One of this QStandardItem consists of data, part of which i want to highlight (add bold or strikeout or another color).
    This data part is a unique id which i will find with regexp.
    So the main question is how to add some styling to only PART of DATA (not the whole cell, not whole QStandardItem, but only part of its text).
    Thanks in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,906
    Thanks
    275
    Thanked 799 Times in 788 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to set several fonts for one Qstandarditem (different fonts for parts of text

    You can try creating the string using Rich Text Format, but if QTableView or whatever you are using to display your model doesn't support it, then you are out of luck. Your only option at that point is to derive a QStyledItemDelegate that supports Rich Text and install that on the appropriate column(s) of your view.

    Here's a StackOverflow question with both C++ and Python implementations you might be able to adapt. (See the answers, not the original question).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 31st October 2014, 07:32
  2. X11 fonts
    By warchild in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2013, 19:35
  3. Adding Arabic fonts and CJK (China Japan Korean) fonts
    By kishore7771 in forum Qt Programming
    Replies: 0
    Last Post: 30th July 2013, 18:33
  4. Replies: 2
    Last Post: 26th December 2012, 01:03
  5. Qt Creator export text editor fonts & colors
    By korwin in forum Qt Tools
    Replies: 0
    Last Post: 14th September 2012, 11:06

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.