PDA

View Full Version : Multiple Font in One Column of QTreeWidgetItem



santosh.kumar
21st February 2014, 03:36
Hi

I am using Qt on MacOS. My software requirement is that We are displaying text in two line, First line will be in Bold Font and in second line, we are using small font,

small sample code for this:

QString strPath = QString(pEntry->cFilePath,pEntry->nPathLen/2);
QString tmpFileName = "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:'Lucida Grande'; font-size:11pt; font-weight:200; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; \">";
tmpFileName = tmpFileName + strFileName + "</span></p>\n";
tmpFileName +="<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;\">" + strPath + "</p>\n";

QTreeWidgetItem *pItem = new QTreeWidgetItem;
QLabel *pLabel = new QLabel;
pLabel->setAutoFillBackground(true);
pLabel->setText(tmpFileName);

treeWidget->setItemWidget(pItem,0,pLabel);


This sample code is correctly show the text in QTreeWidgetItem in two line using HTML tag and QLabel. But After adding few hundred QTreeWidgetItem in QTreeWidget, it started disappear the first column text, when I am moving the vertical scrollbar, But when resize the column 1, using draging column, it immedietly update and view the text in QTreeWidget.

I searched this problem in google, i found one problem here link...
http://www.qtcentre.org/archive/index.php/t-589.html

it solution is the use QItemdelegate and customize setModelData,
But program is developed is that fashion that, in this stage we can't use QItemDelegate to change whole program.

I need some help to fix this bug without using QItemDelegate.

I also see the following link:
http://qt-project.org/doc/qt-4.8/qtreewidget.html#setItemWidget

But no luck.

Kindly tell me the solution for this as we are stuck at this point.


Note: I have attached the screenshot regarding this Bug. Some Item of QTreeWidgetItem display and some Item of QTreeWidgetItem don't display,

Kindly reply for the solution..

anda_skoa
21st February 2014, 08:14
The item delegate approach has nothing to do with setModelData() in your case, you are not trying to get an alternative cell editor.

Instead of abusing setItemWidget(), create a delegate for that column and draw the text directly into the painter.
Either two lines manually, switching font between them, or using QTextDocument to render the HTML you have.

And I have a certain deja vue: http://www.qtcentre.org/threads/58129-Problem-while-using-setItemWidget-in-QTreeWidget

Cheers,
_