Results 1 to 3 of 3

Thread: Unset Data by role

  1. #1
    Join Date
    Dec 2016
    Posts
    15
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Unset Data by role

    Hello,

    I currently set the background role for a cell in the following way. There is also string data in the cell that I have set using setItem.

    model->setData(index, QColor(R,G,B),Qt::BackgroundRole);

    Now I'm trying to 'unset' just the color I set to the model.
    Is there a 'clear' to just clear the background role specified for the cell?

    Thanks,
    Padma

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unset Data by role

    Hi, maybe set QColor() or QPalette::color(QPalette::Background)?

    Ginsengelf

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Unset Data by role

    Now I'm trying to 'unset' just the color I set to the model.
    When you call setData(), you are changing the model, so the only way to "unset" the model is to call setData() again with the default color. The model doesn't have any memory of its state before you made the change so it can't undo a change on its own.

    If you don't know the default color, simply call data() with Qt:: BackgroundRole -before- you make any changes to the model. Save this color somewhere so you can use it to restore the original color. An easy way might be to call setData() with Qt:: UserRole and save it there if your model allows that.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    padma (23rd February 2017)

Similar Threads

  1. How is a Defines unset?
    By Rdeserk in forum Qt Tools
    Replies: 1
    Last Post: 28th August 2013, 08:25
  2. Replies: 4
    Last Post: 29th May 2013, 13:56
  3. Replies: 0
    Last Post: 3rd February 2012, 03:05
  4. Replies: 1
    Last Post: 7th December 2011, 01:04
  5. Role Text for the Widgets
    By Rakesh_Kumar in forum Qt Programming
    Replies: 17
    Last Post: 2nd April 2009, 14:34

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.