Results 1 to 3 of 3

Thread: Different text styles in a single cell of QTableView?

  1. #1
    Join Date
    Jan 2009
    Posts
    20
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Different text styles in a single cell of QTableView?

    Is it possible to have different text styles in a single cell of QTableView?

    I'm using QTableView and, after some effort, a custom model (subclass of QAbstractTableModel). Each row should correspond to a single employee, with image in the first column, department in the third, but multi-line text in the second column as 'depicted' below. I want to make line1 bold/bigger text/different colour. Any pointers will be appreciated.

    Qt Code:
    1. --------------------------------------------------
    2. | image | Name Surname (line1) | Department |
    3. | | employeeID, email (line2) | |
    4. --------------------------------------------------
    To copy to clipboard, switch view to plain text mode 

    BTW, will this work with expected results (2 lines) on all platforms?
    Qt Code:
    1. QString cellText;
    2. cellText = line1 + "\n" + line2;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Different text styles in a single cell of QTableView?

    You need to use a delegate. Check out this HTML delegate. The HTML would be:
    Qt Code:
    1. cellText = QString("<b>") + line1 + QString("</b><br />") + line2;
    To copy to clipboard, switch view to plain text mode 

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

    xfurrier (23rd August 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    20
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Different text styles in a single cell of QTableView?

    Absolutely right - thanks for the pointer.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. How to tell if QTableView cell is visible ?
    By steviekm3 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2009, 10:04
  3. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49

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.