PDA

View Full Version : Different text styles in a single cell of QTableView?



xfurrier
20th August 2009, 18:49
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.



--------------------------------------------------
| image | Name Surname (line1) | Department |
| | employeeID, email (line2) | |
--------------------------------------------------


BTW, will this work with expected results (2 lines) on all platforms?


QString cellText;
cellText = line1 + "\n" + line2;

numbat
21st August 2009, 11:07
You need to use a delegate. Check out this HTML delegate (http://www.qtcentre.org/forum/f-newbie-4/t-html-and-qstandarditem--22863.html). The HTML would be:


cellText = QString("<b>") + line1 + QString("</b><br />") + line2;

xfurrier
23rd August 2009, 07:49
Absolutely right - thanks for the pointer.