Results 1 to 4 of 4

Thread: [RESOLVED] Problems chaning background color of QTableWidgetItem

  1. #1
    Join Date
    May 2011
    Posts
    14
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question [RESOLVED] Problems chaning background color of QTableWidgetItem

    Good Day Everyone,

    I just upgraded to QT 4 this week, and still learning some of the features.

    Currently my problem is changing the background color of a QTalbeWidgetItem

    Here is what I am doing:

    dataTable->itemat( row , col ) -> setBackground ( QBrush( Qt::cyan) ) ;

    (where dataTable is a QTableWidget)

    The good news is a cell does appear in cyan, however it is the wrong cell, and it's always the cell at 0 , 0 no matter what row , col I use.

    If somebody could help me figure out what I'm doing wrong it would be greatly appreciated.

    Let me know if more info is needed on this problem.

    Thank you,

    Sarol
    Last edited by Sarol; 15th June 2011 at 19:07. Reason: spelling corrections

  2. #2
    Join Date
    May 2011
    Posts
    14
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: [RESOLVED] Problems chaning background color of QTableWidgetItem

    I figured out how to do what I needed but still not sure why the above method does not work. Here is I changed:

    Original Code:
    dataTable->itemat( row , col ) -> setBackground ( QBrush( Qt::cyan) ) ;

    New Code:
    dataTable->item( row , col ) ->setData( Qt::BackgroundRole , QBrush( Qt::cyan ) ) ;

    And now its all working...
    Last edited by Sarol; 15th June 2011 at 19:07.

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

    Default Re: [RESOLVED] Problems chaning background color of QTableWidgetItem

    The error must have been elsewhere since this is the implementation of setBackground:
    Qt Code:
    1. inline void setBackground(const QBrush &brush) { setData(Qt::BackgroundRole, brush); }
    To copy to clipboard, switch view to plain text mode 

    Your row and col must have had wrong values.
    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.


  4. #4
    Join Date
    May 2011
    Posts
    14
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: [RESOLVED] Problems chaning background color of QTableWidgetItem

    well after looking at my original code I found what I was doing wrong.

    I was doing:
    dataTable->itemat( row , col ) -> setBackground ( QBrush( Qt::cyan) ) ;

    When I should have been doing:
    dataTable->item( row , col ) -> setBackground ( QBrush( Qt::cyan) ) ;

    Now on to other issues.

Similar Threads

  1. Change text color in QTableWidgetItem
    By npascual in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2011, 17:03
  2. Replies: 0
    Last Post: 31st August 2010, 06:11
  3. Problems editing QTableWidgetItem
    By SCV in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2009, 21:06
  4. Setting a highlight text color for QTableWidgetItem
    By Hiba in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2007, 10:51
  5. 3 Different Color for in QTablewidgetItem
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2006, 11:38

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.