Results 1 to 2 of 2

Thread: about newline

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default about newline

    I want to implement the follow picture,and I meet some question,I create a new PluginDelegate,but I don't know how to create newline in same index.maybe my solution is wrong,could someone help me?
    Qt Code:
    1. class PluginDelegate : public QAbstractItemDelegate {
    2. public:
    3. PluginDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){}
    4. void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const{
    5. if(option.state & QStyle::State_Selected){
    6. painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
    7. }
    8. QIcon ic = QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
    9. QString txt = index.data(Qt::DisplayRole).toString();
    10. QString txt1 = index.data(Qt::DisplayRole).toString();
    11. QRect r = option.rect.adjusted(2, 2, -2, -2);
    12. ic.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
    13. r = r.adjusted(r.height()+20, 0, 0, 0);
    14. painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, txt, &r);
    15. r = r.adjusted(r.height()+20+50, 0, 0, 0);
    16. painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, txt1, &r);
    17.  
    18. }
    19. QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const{
    20. return QSize(200, 52); // very dumb value
    21. }
    22.  
    23. };
    24. int main(int argc, char *argv[])
    25. {
    26. QApplication app(argc, argv);
    27. model.setRowCount(5);
    28. model.setColumnCount(2);
    29. model.setData(model.index(0, 0), QPixmap(":/butterfly.png"), Qt::DecorationRole);
    30. model.setData(model.index(0, 0), "frist");
    31. model.setData(model.index(0, 0), "Time");
    32.  
    33. lv.setModel(&model);
    34. lv.setItemDelegate(new PluginDelegate(&lv));
    35. lv.setAlternatingRowColors(true);
    36. lv.show();
    37. return app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by wysota; 9th September 2009 at 13:12. Reason: missing [code] tags

Similar Threads

  1. QTextBrowser NewLine
    By QbelcorT in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2009, 08:34
  2. Newline char combination in qstring
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2008, 12:18
  3. Windows newline
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 01:34

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.