+ Reply to Thread
Results 1 to 3 of 3

Thread: Unset Data by role

  1. #1
    Join Date
    Dec 2016
    Posts
    9
    Thanks
    1
    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
    Posts
    291
    Thanks
    9
    Thanked 35 Times in 33 Posts
    Qt products
    Qt4
    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
    3,079
    Thanks
    190
    Thanked 484 Times in 475 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    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.
    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)

+ Reply to Thread

Similar Threads

  1. How is a Defines unset?
    By Rdeserk in forum Qt Tools
    Replies: 1
    Last Post: 28th August 2013, 07:25
  2. Replies: 4
    Last Post: 29th May 2013, 12:56
  3. Replies: 0
    Last Post: 3rd February 2012, 02:05
  4. Replies: 1
    Last Post: 7th December 2011, 00:04
  5. Role Text for the Widgets
    By Rakesh_Kumar in forum Qt Programming
    Replies: 17
    Last Post: 2nd April 2009, 13: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