How can I have children that have a second column of data? I am creating a table of contents and the parent items will properly show the second column with the page number but children do not. I have tried making the child page number a child of the parent page number. I read somewhere that children only get 1 column. Is there a way around this? I tried using HTML so that the title was aligned left and the page was aligned right in 1 column for both parent and child. However it seems the QTextDocument (inserted using QStyledItemDelegate) does not want to use the full width of the QTreeView (all of the text is together). Also, the QTextDocument does not highlight when a row is selected in the QTreeView.

Any Suggestions?


Qt Code:
  1. QString data = QString::fromUtf8(title) + "<span style=font-weight:bold;text-align:right;float:right>" + QString::number(page) + "</span>";
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void StyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
  2. QStyleOptionViewItemV4 options = option;
  3. initStyleOption(&options, index);
  4.  
  5. painter->save();
  6. qDebug() << option.rect.width();
  7. doc.setTextWidth(option.rect.width());
  8. doc.setHtml(index.data().toString());
  9. //painter->save();
  10. painter->translate(option.rect.topLeft());
  11. doc.drawContents(painter,QRect(QPoint(0,0),option.rect.size()));
  12. painter->restore();
  13. }
  14.  
  15. QSize StyledItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
  16. QStyleOptionViewItemV4 options = option;
  17. initStyleOption(&options, index);
  18.  
  19. doc.setHtml(options.text);
  20. doc.setTextWidth(options.rect.width());
  21.  
  22. QSize size = QStyledItemDelegate::sizeHint(option, index);
  23. return QSize(size.width() > doc.idealWidth() ? size.width() : doc.idealWidth(),
  24. size.height() > doc.size().height() ? size.height() : doc.size().height());
  25. }
To copy to clipboard, switch view to plain text mode