Results 1 to 3 of 3

Thread: How to move QPixmap in QTableView

  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Question How to move QPixmap in QTableView

    Hi!
    I have QTableView and insert QPixmap and QString using QAbstractTableModel:

    Qt Code:
    1. QVariant CurrencyModel::data(const QModelIndex &index, int role) const
    2. {
    3.  
    4. if (!index.isValid())
    5. return QVariant();
    6. if (role == Qt::TextAlignmentRole) {
    7. return int(Qt::AlignBottom);
    8. }
    9. else if (role == Qt::DisplayRole) {
    10. sz=5*index.row();
    11. QString amount = currencyAt(index.column()+sz);
    12. return amount;
    13. }
    14. else if (role == Qt::DecorationRole) {
    15. sz=5*index.row();
    16. QPixmap pixmap;
    17. QString amount = currencyAt(index.column()+sz);
    18. qDebug()<<amount;
    19. if(pixmap.isNull()) pixmap.load("radio.jpg");
    20. pixmap.load(amount +".jpg");
    21. pixmap=pixmap.scaled(50, 50, Qt::KeepAspectRatio);
    22. return pixmap;
    23. }
    24. return QVariant();
    25. }
    26. QString CurrencyModel::currencyAt(int offset) const
    27. {
    28. if(offset >= currencyMap.size()) return "";
    29. return (currencyMap.begin() + offset).key();
    30. }
    To copy to clipboard, switch view to plain text mode 
    Looks like in the picture:
    Снимок.png
    Pixmap always inserted in left. But need pixmap top, text under the pixmap. How to do that?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to move QPixmap in QTableView

    A custom delegate is one option. If you are actually displaying a list then the QListView in IconMode might be a better choice.

  3. #3
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: How to move QPixmap in QTableView

    Thank you very mach! I displaying a list then the QListView in IconMode. It's really better.

Similar Threads

  1. QTableView how to move columns with code
    By Marco in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2016, 12:00
  2. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 11:45
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34
  5. Replies: 5
    Last Post: 9th April 2007, 14:26

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.