Results 1 to 5 of 5

Thread: Rich text in table view

  1. #1
    Join Date
    Mar 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Rich text in table view

    How to display rich text in table view?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rich text in table view

    you can try this, a little bit tricky, but works
    Qt Code:
    1. MyItemDelegate::MyItemDelegate(QObject *object)
    2. : QItemDelegate(object)
    3. {
    4. m_label = new QLabel();
    5. m_label->setTextFormat(Qt::RichText);
    6. }
    7.  
    8. MyItemDelegate::~MultistringsItemDelegate()
    9. {
    10. delete m_label;
    11. m_label = 0;
    12. }
    13.  
    14. QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    15. {
    16. Q_UNUSED(option);
    17. Q_UNUSED(index);
    18. return new QLineEdit(parent);
    19. }
    20.  
    21. void MyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    22. {
    23. QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
    24. if (!lineEdit)
    25. return;
    26. model->setData(index, lineEdit->text());
    27. model->setData(index, QString("<span style=\" color:#0ff000;\">%1</span>").arg(lineEdit->text()), Qt::DisplayRole);
    28. }
    29.  
    30. void MyItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
    31. {
    32. m_label->setText(text);
    33. QPalette pal(m_label->palette());
    34. pal.setColor(QPalette::Active, QPalette::Window, option.state & QStyle::State_Selected ? pal.color(QPalette::Highlight) : pal.color(QPalette::Base));
    35. m_label->setPalette(pal);
    36. m_label->resize(option.rect.size());
    37. QPixmap p = QPixmap::grabWidget(m_label);
    38. painter->drawPixmap(option.rect, p);
    39. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rich text in table view

    Or you can take a look at the "similar threads" table on the bottom of the thread page.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Rich text in table view

    thank u so much guys!

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rich text in table view

    you can also make like this
    Qt Code:
    1. ...
    2. void MyItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
    3. {
    4. Q_UNUSED(rect);
    5. doc.setHtml(text);
    6. doc.drawContents(painter, option.rect);
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following user says thank you to spirit for this useful post:

    neuronet (8th December 2015)

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Doubt about QTextEdit and Rich Text
    By iamjayanth in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 08:11
  3. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56
  4. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  5. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45

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.