Results 1 to 8 of 8

Thread: change color/focus in qtablewidget

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default change color/focus in qtablewidget

    I try to explain my doubt.

    I have six tables (6 qtablewidget) and a button.

    When I push the button, it executes some code and I would like that the focus of the six tables goes to a determinate row,col and the color of the row change.

    Is that possible? Could you give some help?

    Many thanks and sorry for my english!
    Last edited by mmm286; 4th March 2010 at 17:17.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change color/focus in qtablewidget

    You will need to subclass the QTAbleWdget and add some variable for the row/col you want to change the color of.
    Then use delegate to change the color of the row/col
    When you click the button, perform your actions and then update the variable

  3. #3
    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: change color/focus in qtablewidget


  4. #4
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: change color/focus in qtablewidget

    Thanks

    I try:

    Qt Code:
    1. hitem->setBackground(QBrush(QColor(255, 0, 0, 7)));
    2. tabla->setVerticalHeaderItem(3, hitem); // item is placed on the header of row r
    3. tabla->setHorizontalHeaderItem(1, hitem);
    4. tabla->setItem(1,1,hitem);
    To copy to clipboard, switch view to plain text mode 

    If I do this, the verticalheader and the horizontalHeader changes the color but the cell (1,1) doesnt change.
    Any help?

    EDIT
    --------------------

    Well, I do it.
    tabla->item(estara-1,0)->setBackground(QBrush(hola.fromHsv(0,75,255,255) ))


    The other question.
    The tablewidget is short, so when my program finds the appropiate cell I would like to the table moves automatically to this cell. This is possible?

    Many thanks and sorry for my english!
    Last edited by mmm286; 5th March 2010 at 12:37.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change color/focus in qtablewidget


  6. #6
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change color/focus in qtablewidget

    Or even use a style sheet.
    Qt Code:
    1. tableview.setStyleSheet("background-color: wathevercolor")
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change color/focus in qtablewidget

    To set the background color of selected text or item:
    Qt Code:
    1. mytableWidget.setStyleSheet(selection-background-color : acolor")
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to toutarrive for this useful post:

    pavanbarot (11th August 2010)

  9. #8
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change color/focus in qtablewidget

    Quote Originally Posted by toutarrive View Post
    To set the background color of selected text or item:
    Qt Code:
    1. mytableWidget.setStyleSheet(selection-background-color : acolor")
    To copy to clipboard, switch view to plain text mode 
    if i want to change the row's background which i selected with a image? how should i do?

Similar Threads

  1. Replies: 2
    Last Post: 17th July 2010, 22:07
  2. Replies: 3
    Last Post: 22nd January 2010, 17:46
  3. Change Color of Focus Frame
    By crybaby in forum Newbie
    Replies: 3
    Last Post: 30th October 2009, 08:02
  4. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25
  5. Menu bar background color focus
    By user_mail07 in forum Qt Tools
    Replies: 0
    Last Post: 18th May 2007, 02:25

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.