Results 1 to 5 of 5

Thread: Why isnt MyItemDelegate working??? please help!

  1. #1
    Join Date
    Sep 2009
    Posts
    64

    Default Why isnt MyItemDelegate working??? please help!

    so i am trying to get an icon to fill up the space of a QTableWidgetItem. so i subclassed the ItemDelegate and set it to my QTableWidget, but still, the icons wont fill out the item in the table.

    here is my code... below is what i have at the top of my *.cpp file

    Qt Code:
    1. class MyItemDelegate: public QItemDelegate
    2. {
    3. public:
    4. MyItemDelegate(QObject* pParent = 0) : QItemDelegate(pParent)
    5. {
    6. std::cout<<"INSIDE DELEGATE PAINT~~~~~~~~~~~~~~~~~~"<<std::endl;
    7. }
    8. void MyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    9. {
    10. QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    11. drawBackground(painter, option, index);
    12. drawDecoration(painter, option, option.rect, icon.pixmap(option.rect.size()));
    13. drawFocus(painter, option, option.rect);
    14. std::cout<<"INSIDE DELEGATE PAINT"<<std::endl;
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    and here is where i am setting the delegate to my table

    Qt Code:
    1. mThumbArea->setItemDelegate(new MyItemDelegate(mThumbArea));
    To copy to clipboard, switch view to plain text mode 

    here is where i add the icon to the table

    Qt Code:
    1. QTableWidgetItem *newItemImage = new QTableWidgetItem(QIcon(filename),"");
    2. mThumbArea->setItem(0,0,newItemImage);
    To copy to clipboard, switch view to plain text mode 

    filename is valid, and the item is successfully added to the table, its just that the icon is much too small... what is happening!!!

  2. #2
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Why isnt MyItemDelegate working??? please help!

    QIcon.pixmap() says:
    Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.
    Maybe go:
    Qt Code:
    1. icon.pixmap(QSize(50,50));
    To copy to clipboard, switch view to plain text mode 
    Just to see if it get's bigger?

  3. #3
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Why isnt MyItemDelegate working??? please help!

    No that didnt change the size. the icon is still scaled down and shoved to the left side of the item box.

  4. #4
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Why isnt MyItemDelegate working??? please help!

    anyone have any ideas? ive been banging my head against my computer all day yesterday and today... i cant seem to figure out what the problem is!

  5. #5
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Why isnt MyItemDelegate working??? please help!

    do i have to continuously set my item delegate whenever i am trying to add an item to my table or do i only need to set the item delegate once in the constructor of my class... seriously... i dont know what im doing wrong... trying EVERYTHING!

Similar Threads

  1. My first app not working
    By Noks in forum Newbie
    Replies: 6
    Last Post: 2nd February 2010, 17:34
  2. Working with QObject
    By been_1990 in forum Qt Programming
    Replies: 15
    Last Post: 20th June 2009, 22:12
  3. Alt+F4 isnt grabbed by QWidget::grabKeyboard()
    By BlackHornet in forum Qt Programming
    Replies: 1
    Last Post: 19th May 2009, 11:19
  4. why isnt my button showing?
    By IsleWitch in forum Newbie
    Replies: 4
    Last Post: 7th October 2007, 19:28
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 02:02

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.