Results 1 to 5 of 5

Thread: how to specify item's style in QTableView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    21
    Thanked 3 Times in 3 Posts

    Default how to specify item's style in QTableView?

    hi, I'm writing style sheet for QTableView and need to specify single item's appearance. how to change single item's style, such as border and background color? if the item has no special state compared with other items. can we set property like QWidgets to items in the view?

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

    Default Re: how to specify item's style in QTableView?

    Give that item a unique object name and use it as a selector in CSS.

  3. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    21
    Thanked 3 Times in 3 Posts

    Default Re: how to specify item's style in QTableView?

    Quote Originally Posted by Lykurg View Post
    Give that item a unique object name and use it as a selector in CSS.
    Sadly QStandardItem is not a subclass of QObject so no object name could be given, and QTableView : : item {...} in style sheet is a type of sub-control other than a widget.

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

    Default Re: how to specify item's style in QTableView?

    I guess delegates would be better to use.
    You can always setData of item through some role, and use this role to do your decoration in the delegate

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

    Default Re: how to specify item's style in QTableView?

    Quote Originally Posted by nifei View Post
    Sadly QStandardItem is not a subclass of QObject so no object name could be given
    Ups, you are right, but then - not tested! - create your subclass which also have QObject as a parent, and CSS should work.

Similar Threads

  1. Some menubar items can not be clicked
    By richardander in forum Qt Programming
    Replies: 4
    Last Post: 11th March 2009, 00:26
  2. Use delegate to draw different type of items
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 13:16
  3. checkable items in QTableView
    By cgorac in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2008, 22:45
  4. Scrolling items in QTableView
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2007, 12:59
  5. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20

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.