Results 1 to 4 of 4

Thread: QTableWidget Pixmap problem

  1. #1
    Join Date
    Jun 2008
    Posts
    64
    Thanks
    7
    Qt products
    Qt3 Qt4

    Default QTableWidget Pixmap problem

    How can I set a background pixmap in a cell of QTableWidget?

    in QT3 , there is a
    Qt Code:
    1. void QTable::setPixmap ( int row, int col, const QPixmap & pix ) [virtual]
    To copy to clipboard, switch view to plain text mode 

    If I change the QTable to QTableWidget, how can I complete the above task?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Pixmap problem

    There are methods for setting a background texture or an icon, but I don't think you want that. You can subclass QTableWidgetItem and make it paint the pixmap.

  3. #3
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTableWidget Pixmap problem

    Maybe its possible to use the following function on a QTableWidget:
    Qt Code:
    1. QTableWidgetItem * QTableWidget::item ( int row, int column ) const
    To copy to clipboard, switch view to plain text mode 
    Returns the item for the given row and column if one has been set; otherwise returns 0.


    after you got the QTableWidgetItem, use this function on it:
    Qt Code:
    1. void QTableWidgetItem::setIcon ( const QIcon & icon )
    To copy to clipboard, switch view to plain text mode 
    Sets the item's icon to the icon specified.

    ah by the way a QIcon can be created from a pixmap using the following constructor:
    Qt Code:
    1. QIcon ( const QPixmap & pixmap )
    To copy to clipboard, switch view to plain text mode 


    Correct me if i am wrong, i am currently not working with Qt4, but i remember i did something like this in the past
    Last edited by BrainB0ne; 5th September 2008 at 08:45.
    ..:: Still Standing Strong ::..

  4. #4
    Join Date
    Nov 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableWidget Pixmap problem

    Use setData with Qt:: DecorationRole instead, to display an entire picture.

    Qt Code:
    1. QPixmap pixmap = myFunctionToLoadPixmap();
    2. newItem->setData(Qt::DecorationRole, pixmap);
    3. m_verticalRoadSignWidget->ui.mruTableWidget->setItem(0, 0, newItem);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problem about porting Q3Table to QTableWidget
    By batileon in forum Qt Programming
    Replies: 0
    Last Post: 28th August 2008, 11:18
  2. QTableWidget setSpan text display problem
    By sureshbabu in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2008, 16:14
  3. Smooth pixmap transform in QGraphicsView problem
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2007, 16:47
  4. experiencing problem at printing out QTableWidget
    By rmagro in forum Qt Programming
    Replies: 9
    Last Post: 27th June 2007, 16:04
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 00:10

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.