Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to change font color of QListWidgetItem when it is in edit mode
QtWS25 Last Chance

[Solved]How to change font color of QListWidgetItem when it is in edit mode

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 10.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bekos
    wrote on last edited by
    #1

    Hello there guys!
    Again, I am having hard time to do something in Qt. I have a QListWidget with the following StyleSheet for its items:
    @
    QListView:item:selected { color: black; background-color: orange; }
    @
    Using the above, the items in the list have a black font when I select one of them.
    What I want now is to have a different font color (white) when one of them is in edit mode.
    Is there anyway to do this with CSS? The only solution I can think of is using C++ code and is the following:
    Set the font color to (white) using a StyleSheet when I am entering the edit mode. (in my code I call QListWidget::editItem(). So I will set the new styleSheet before calling this). Then, I will use this connection to catch the closeEditor signal and reset the item color somehow using a styleSheet:
    @
    connect( _stateListWidget->itemDelegate(), SIGNAL(closeEditor(QWidget*)), this, SLOT(editorWasClosed(QWidget*)) );
    @

    I don't like this solution. There must be an easier way to do this. Any ideas? Thank you!

    Cheers!

    Edit: the square-bracket version of the code tag does not work properly for the forum, use the @ tags instead please; Andre

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What you might try, is use the fact that the delegate is a child widget of the viewport. That means, that you should be able to do something along these lines:

      @
      QWidget QWidget { color: red; background-color: white }
      @
      and set that on the viewport.

      I did not try this myself, but I think something like this should work.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bekos
        wrote on last edited by
        #3

        Ohh my god... you rock :D It worked! :D I think I need to read some Qt tutorials or get a Qt book because I don't know a lot of basic stuff. I didn't know about viewport for example :P
        Thanks again my friend!

        Cheers!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved