Results 1 to 5 of 5

Thread: Icon on right side of a call in qtableview filled by model

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Qt products
    Qt5
    Platforms
    MacOS X Windows
    Thanks
    5

    Question Icon on right side of a call in qtableview filled by model

    I have a text and an icon.
    I want to display the text in the left side of the cell and icon to the extreme right of the cell.
    How can I do this?

    The code I have included is as follows
    Qt Code:
    1. model = new ItemModel(5, 3, this);
    2. QPixmap arrowIcon(":/arrowBig.png");
    3. int i=0;
    4. for (QStringList::iterator it= rowName.begin(); it != rowName.end(); ++it)
    5. {
    6. QModelIndex index = model->index(i++,columnNameNum,QModelIndex());
    7. QString current = *it;
    8. qDebug()<<current;
    9.  
    10. model->setData(index,arrowIcon,Qt::DecorationRole);
    11.  
    12. model->setData(index,current);
    13.  
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class ItemModel : public QStandardItemModel
    2. {
    3. public:
    4. ItemModel(int rows, int columns, QObject *parent = 0)
    5. :
    6. QStandardItemModel(rows, columns, parent)
    7. {}
    8.  
    9. QVariant data(const QModelIndex &index, int role) const
    10. {
    11. if (role == Qt::TextAlignmentRole) {
    12. return Qt::AlignLeft; // <- Make alignment look different, i.e.
    13. // <- text at the bottom.
    14. }
    15. else {
    16. return QStandardItemModel::data(index, role);
    17. }
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 

    thanks in advance
    Last edited by anda_skoa; 6th February 2015 at 12:15. Reason: missing [code] tags

Similar Threads

  1. How to call a static method of java from c++ side?
    By stereoMatching in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 31st December 2013, 15:54
  2. QTreeWidget Right side arrow icon
    By karankumar1609 in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2013, 00:32
  3. Event handlers for QTableView model / selection model.
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2011, 17:57
  4. Replies: 2
    Last Post: 24th July 2009, 22:09
  5. Replies: 5
    Last Post: 15th February 2008, 02:54

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
  •  
Qt is a trademark of The Qt Company.