Results 1 to 9 of 9

Thread: How to get a QPixmap from a QTableWidgetItem?

  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Angry How to get a QPixmap from a QTableWidgetItem?

    Sorry guys & girls,

    it's late and I'm tired but I have to fix something in my code, something where I could not figure out where I'm wrong.

    The question is simple: How can I get a QPixmap from a QTableWidgetItem?

    I have tried so many already but's all not working. Guess I should go to bed, but I'm really under pressure with that.

    Why this code for example

    Qt Code:
    1. QPixmap pixmap = QPixmap::grabWidget( currentItem(), 0, 0, 158, 18 );
    To copy to clipboard, switch view to plain text mode 
    gives me:

    Qt Code:
    1. error: no matching function for call to ‘QPixmap::grabWidget(QTableWidgetItem*, int, int, int, int)’
    2. .....
    3. candidates are: static QPixmap QPixmap::grabWidget(QWidget*, const QRect&)
    4. static QPixmap QPixmap::grabWidget(QWidget*, int, int, int, int)
    To copy to clipboard, switch view to plain text mode 
    Where I'm to blind to the the trees in the forrest tonight?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    See the QTableWidgetItem::data() with the decoration role.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    A QTableWidgetItem is not a QWidget, so grabWidget does not work.
    What do you want to achieve? Do you want to make a pixmap of one item in the table?

  4. #4
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    Some days are like that ...

    Quote Originally Posted by tbscope View Post
    A QTableWidgetItem is not a QWidget, so grabWidget does not work.
    I know, I should stop for today, I'm so tired ...

    Quote Originally Posted by tbscope View Post
    What do you want to achieve? Do you want to make a pixmap of one item in the table?
    Yes, that's exactly what I like to do ...

    Any idea how to do that?

  5. #5
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Re: How to get a QPixmap from a QTableWidgetItem?

    Quote Originally Posted by Lykurg View Post
    See the QTableWidgetItem::data() with the decoration role.
    Thanks Lykurg!

    Have tried this now ...

    Qt Code:
    1. QPixmap TableWidget::selectedPixmap() const
    2. {
    3. if ( !currentItem() )
    4. {
    5. qDebug() << "no item found ...";
    6. return QPixmap();
    7. }
    8. else
    9. {
    10. qDebug() << "current item is" << currentItem();
    11. return currentItem()->data( Qt::DecorationRole ).value<QPixmap>();
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    but's still the same.

    qDebug() returns 'current item is 0x1422a10'
    qDebug() << currentItem()->data( Qt:ecorationRole ) returns ''QVariant(QString, "ArtMatch")'

    But QSize returns 'QSize(-1, -1)'!

    For testing I have tried to set my pixmap from an image with

    Qt Code:
    1. QPixmap pixmap( ":/images/ampel_rot.jpg" );
    To copy to clipboard, switch view to plain text mode 
    With that my programm will work, but I need a pixmap with the content of currentItem()!

    Any other ideas?

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    Ok, I get you wrong. If you need to render a whole item then use QTableWidget::visualItemRect() with QWidget::render() of the table widget.

  7. The following user says thank you to Lykurg for this useful post:

    gboelter (10th October 2010)

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

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    You can call the delegate to render the item.
    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.


  9. The following user says thank you to wysota for this useful post:

    gboelter (10th October 2010)

  10. #8
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: How to get a QPixmap from a QTableWidgetItem?

    Quote Originally Posted by Lykurg View Post
    If you need to render a whole item then use QTableWidget::visualItemRect() with QWidget::render() of the table widget.
    Thanks Lykurg,

    got it working in that way.

    Thank you very much!!!

  11. #9
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a QPixmap from a QTableWidgetItem?

    Quote Originally Posted by wysota View Post
    You can call the delegate to render the item.
    Thanks wysota,

    will try it next time with delegate because I have never used delegate before.

    For now it's fixed with the help from Lykurg.

    I really love the forum here!!!

Similar Threads

  1. Replies: 4
    Last Post: 28th August 2008, 13:13
  2. Replies: 1
    Last Post: 21st August 2008, 07:44
  3. Replies: 5
    Last Post: 9th April 2007, 14:26
  4. QTableWidget QTableWidgetItem
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 6th September 2006, 15:03
  5. Tooltips in QTableWidgetItem
    By Arthur in forum Newbie
    Replies: 2
    Last Post: 26th January 2006, 15:47

Tags for this Thread

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.