[Interest] Setting current item text color via stylesheet in QTableView for SelectRows

Patrick Stinson patrickkidd at gmail.com
Fri Aug 10 21:11:50 CEST 2018


Negative. “current” is not a valid pseudo state, as “focus” is the appropriate pseudo state for the current item.

> On Aug 9, 2018, at 6:15 PM, Reinhardt Behm <rbehm at hushmail.com> wrote:
> 
> Hi Patrick,
> 
> how about:
> QTableView::item:selected
> { color:green; }
> QTableView::item:current
> { color:yellow; }
> 
> -- 
> Best Regards
> 
> Reinhardt Behm
> 
> On Thursday 09 August 2018 10:34:38 you wrote:
>> Thanks again. Actually, what I am trying to do is differentiate between
>> current and selected items so that I can tell which item is current within
>> the selected row. For example, the following paints all selected items with
>> the same text color so you don’t know which one is selected:
>> 
>> QTableView::item:focus {
>>    color: yellow;
>> }
>> 
>>> On Aug 7, 2018, at 11:31 PM, Reinhardt Behm <rbehm at hushmail.com> wrote:
>>> 
>>> Hi Patrick,
>>> 
>>> as I understood you, you want to style a row in a table view. When it is
>>> selected and and current.
>>> 
>>> I would do it like
>>> TableView::item:selected, TableView::item:current
>>> { color:ugly-green; }
>>> 
>>> This is untested.
>>> 
>>>> Thanks again, but I still don’t think you have answered the question.
>>>> 
>>>>> On Aug 7, 2018, at 10:22 PM, Reinhardt Behm <rbehm at hushmail.com <mailto:rbehm at hushmail.com>> wrote:
>>>>> 
>>>>> You can combine attributes:
>>>>> 
>>>>> If needed, logical OR can be expressed using the comma operator:
>>>>> QCheckBox:hover, QCheckBox:checked { color: white }
>>>>> 
>>>>>> On Tuesday 07 August 2018 20:54:58 you wrote:
>>>>>> Thanks for your reply, Reinhardt. Your code acknowledges the selected
>>>>>> item
>>>>>> but I am looking for the current item whether it is selected or not.
>>>>>> 
>>>>>> -Patrick
>>>>>> 
>>>>>>> On Aug 7, 2018, at 6:00 PM, Reinhardt Behm via Interest
>>>>>>> <interest at qt-project.org <mailto:interest at qt-project.org>> wrote:>
>>>>>>> 
>>>>>>> On Tuesday 07 August 2018 16:31:42 Patrick Stinson wrote:
>>>>>>>> Hello!
>>>>>>>> 
>>>>>>>> I have a vanilla QTableView with SingleSelection and SelectRows and
>>>>>>>> am
>>>>>>>> trying to figure out how to set the text color of the current item
>>>>>>>> for
>>>>>>>> both
>>>>>>>> when the row is selected and when it isn’t. This is important so that
>>>>>>>> the
>>>>>>>> user knows which cell will be edited when they hit the enter key and
>>>>>>>> so
>>>>>>>> they can navigate to a new cell using the arrow keys.
>>>>>>>> 
>>>>>>>> It seems that the following will do it, but it doesn’t apply when the
>>>>>>>> row
>>>>>>>> is selected.
>>>>>>>> 
>>>>>>>> QTableView::item:focus {
>>>>>>>> 
>>>>>>>> color: yellow;
>>>>>>>> 
>>>>>>>> }
>>>>>>>> 
>>>>>>>> How can this be done?
>>>>>>>> 
>>>>>>>> Thanks!
>>>>>>>> -Patrick
>>>>>>> 
>>>>>>> Here something is used in a similar case
>>>>>>> 
>>>>>>> TableViewBase {
>>>>>>> 
>>>>>>>  font-size: 18px; font-weight: bold;
>>>>>>>  background-color: white;
>>>>>>> 
>>>>>>> }
>>>>>>> TableViewBase::item {
>>>>>>> 
>>>>>>>  color: black;
>>>>>>>  font-size: 18px; font-weight: bold;
>>>>>>>  background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:
>>>>>>>  0
>>>>>>> 
>>>>>>> #f6f7fa, stop: 1 #dadbde);
>>>>>>> }
>>>>>>> TableViewBase::item:selected {
>>>>>>> 
>>>>>>>  color: white;
>>>>>>>  background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:
>>>>>>>  0
>>>>>>> 
>>>>>>> #606060, stop: 1 #000000);
>>>>>>> }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180810/3941a17b/attachment.html>


More information about the Interest mailing list