PyQt 5.8 changes stylesheet interpretation

190 views
Skip to first unread message

Terry Brown

unread,
Mar 14, 2017, 10:39:22 PM3/14/17
to leo-e...@googlegroups.com
Just confirmed in a Windows 7 VM switching back and forth between PyQt
5.7.1 and 5.8 (Python 3 for both) that stylesheets that work fine in
5.7.1 (my personal one, and EKR Windows Dark) have issues in PyQt 5.8.

My backgrounds are ok, but font sizes are wrong. EKR Dark had light
backgrounds and some fonts aren't sized right, but some are.

I can not google up any reports of this issue, but it might be only
PyQt, not Qt, or just too early to be being reported yet?

So it might be possible to write stylesheets that work in 5.8 and lower
versions, seeing addressed the right way fonts and backgrounds can be
changed, but what a pain.

Haven't looked into it beyond this observation yet.

Cheers -Terry

Milan Melena

unread,
Mar 15, 2017, 4:18:35 AM3/15/17
to leo-editor
Hi,

I have found out, that problem is with selectors using ~= (tilda)

for example:

QLineEdit#lineEdit[style_class ~= 'minibuffer_warning'] {
    background-color: @minibuffer_warning_color;
}

When you try replace all occurences of "~=" with "=" in stylesheet, everything seems work right even in PyQ 5.8.

Milan Melena

Dne středa 15. března 2017 3:39:22 UTC+1 Terry Brown napsal(a):

Terry Brown

unread,
Mar 15, 2017, 8:02:20 AM3/15/17
to leo-e...@googlegroups.com
On Wed, 15 Mar 2017 01:18:35 -0700 (PDT)
Milan Melena <milan....@gmail.com> wrote:

> Hi,
>
> I have found out, that problem is with selectors using ~= (tilda)
>
> for example:
>
> QLineEdit#lineEdit[style_class ~= 'minibuffer_warning'] {
> background-color: @minibuffer_warning_color;
> }

Ah, ok, thanks for the detective work. Leo uses that construct to
emulate HTML-CSS's `class` attribute, which Qt-CSS doesn't have. Or at
least didn't have, maybe it has something like that now. Will have to
see if Qt-CSS supports ~= in some other way now. ~= means "contains".

Cheers -Terry

Terry Brown

unread,
Mar 15, 2017, 8:21:53 AM3/15/17
to leo-e...@googlegroups.com
p.s. search
http://doc.qt.io/qt-5.8/stylesheet-syntax.html
for ~, it seems like it should still work.

Cheers -Terry

alacnorr

unread,
Mar 15, 2017, 9:24:16 AM3/15/17
to leo-editor
Many thanks, Milan,
you are spot on: eliminating the tildes does indeed fix the problem.
Alac

alacnorr

unread,
Mar 15, 2017, 9:24:21 AM3/15/17
to leo-editor
Terry,
I have reported this issue on github twice, 
#435 and #436.
The issue also affects pristine, vanilla Leo
with no theme enabled.
Alac

Milan Melena

unread,
Mar 15, 2017, 10:33:50 AM3/15/17
to leo-editor
Yes, it is a litle mystery for me too.

Dne středa 15. března 2017 13:21:53 UTC+1 Terry Brown napsal(a):

Edward K. Ream

unread,
Mar 15, 2017, 11:02:49 AM3/15/17
to leo-editor
On Wed, Mar 15, 2017 at 4:56 AM, alacnorr <seven.ca...@gmail.com> wrote:
Many thanks, Milan,
you are spot on: eliminating the tildes does indeed fix the problem.

​Alright.  I shall eliminate tildes everywhere in style sheets. Thanks to all for the sleuthing.

Edward

Edward K. Ream

unread,
Mar 15, 2017, 11:14:55 AM3/15/17
to leo-editor
On Wed, Mar 15, 2017 at 10:02 AM, Edward K. Ream <edre...@gmail.com> wrote:

​Alright.  I shall eliminate tildes everywhere in style sheets.

​Done at rev 3488fbe.  Please report any problems pronto. I would like to release Leo 5.5b1 tomorrow.

Edward

Terry Brown

unread,
Mar 15, 2017, 2:59:18 PM3/15/17
to leo-e...@googlegroups.com
Note that that will break styles where the style_class property is more than one identifier. E.g. "minibuffer error" as opposed to "minibuffer". Some of these things won't be easy to see in a quick spot check. Some of these things change dynamically at run time. Border highlighting might be an example.

Cheers -Terry

>Edward

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Terry Brown

unread,
Mar 15, 2017, 3:17:46 PM3/15/17
to leo-e...@googlegroups.com
P.s. depending on how significant the loss of the tilde function turns out to be, best workaround might be to replace tildes at runtime while we wait for what seems to be a Qt bug to be fixed.

It may be something more subtle, like a change in style sheet specificity rules involving tildes. More investigation needed.

Terry Brown

unread,
Mar 15, 2017, 5:19:01 PM3/15/17
to leo-editor
Note that that will break styles where the style_class property is more than one identifier. E.g. "minibuffer error" as opposed to "minibuffer". Some of these things won't be easy to see in a quick spot check. Some of these things change dynamically at run time. Border highlighting might be an example.

(Sent this from email but don't see it despite seeing my p.s.)

Edward K. Ream

unread,
Mar 15, 2017, 7:00:59 PM3/15/17
to leo-editor
On Wed, Mar 15, 2017 at 4:19 PM, Terry Brown <terry...@gmail.com> wrote:
Note that that will break styles where the style_class property is more than one identifier. E.g. "minibuffer error" as opposed to "minibuffer". Some of these things won't be easy to see in a quick spot check. Some of these things change dynamically at run time. Border highlighting might be an example.

​Terry, what do you suggest we do?  I can move the tilde-less stylesheet to a branch, or leave things as they are.

Edward

Terry Brown

unread,
Mar 15, 2017, 9:36:49 PM3/15/17
to leo-e...@googlegroups.com
On Wed, 15 Mar 2017 18:00:57 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

If taking the tildes out hasn't broken border highlighting (I don't
usually use it anyway) then I guess leave it for now. Might have been
easier taking them out at runtime, in terms of being a one liner we
could revert if the issue gets fixed. I posted this to the PyQt list:

Hi - I think there's a problem with ~= in stylesheets in PyQt 5.8.
The attached program illustrates the issue (also here, same code:
https://gist.github.com/tbnorth/76191db825cc49dcca296ffb8d777047)

It seems 5.8 stops parsing the stylesheet as soon as it sees ~=,
whereas < 5.8 acts as expected (described in docstring of code).

Any thoughts much appreciated,

Thanks, Terry

but I guess it could be a Qt issue rather than a PyQt issue.

Cheers -Terry

Edward K. Ream

unread,
Mar 16, 2017, 5:44:21 AM3/16/17
to leo-editor
On Wed, Mar 15, 2017 at 8:36 PM, Terry Brown <terry...@gmail.com> wrote:

If taking the tildes out hasn't broken border highlighting (I don't
usually use it anyway) then I guess leave it for now. 

​It looks like removing tildes has broken background highlighting in the status area.  With my unchanged myLeoSettings.leo, the stylesheets with tildes code shows failed searches in red, and successful searches in blue. The stylesheets without tildes show the default background colors always.

This is an essential feature for me. For awhile I thought the find commands were broken.

find.showStatus sets these background colors by calling frame.putStatusLine, which calls QtStatusLineClass.put. qsl.put does:

    c.styleSheetManager.mng.remove_sclass(w, ['info', 'fail'])
    c.styleSheetManager.mng.add_sclass(w, status)
    c.styleSheetManager.mng.update_view(w)
       # force appearance update

I'll see what I can deduce.

If I can't fix this quickly I'll restore the tildes so I can release 5.5b1 asap.  We can discuss this further before 5.5 final.

Edward

Edward K. Ream

unread,
Mar 16, 2017, 6:13:26 AM3/16/17
to leo-editor
On Thu, Mar 16, 2017 at 4:44 AM, Edward K. Ream
<edre...@gmail.com> wrote:
​It looks like removing tildes has broken background highlighting in the status area.

​Rev 383484 restores leoSettings.leo from an earlier rev so that it has tildes again. With only this change, the essential background highlighting in the status area works again.

I suspect that there is a bug in the stylesheet manager class relating to tildes. The bug might be subtle.

I didn't write this code, and I don't want to touch it so soon before b1.  Terry, if you can fix the problem quickly, we can remove tildes from leoSettings.leo before b1. It's up to you.

Edward

Terry Brown

unread,
Mar 16, 2017, 8:49:06 AM3/16/17
to leo-e...@googlegroups.com
On Thu, 16 Mar 2017 05:13:24 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Mar 16, 2017 at 4:44 AM, Edward K. Ream
> <edre...@gmail.com> wrote:
>
> ​It looks like removing tildes has broken background highlighting in
> the status area.
>
> ​Rev 383484 restores leoSettings.leo from an earlier rev so that it
> has tildes again. With only this change, the essential background
> highlighting in the status area works again.
>
> I suspect that there is a bug in the stylesheet manager class
> relating to tildes. The bug might be subtle.

I think the blame lies entirely with Qt.
http://doc.qt.io/qt-5.8/stylesheet-syntax.html clearly describes the
use ~= just as we've been using it, without problems, prior to 5.8.

For technical users, I'd say the best solution is

pip3 install "PyQt5<5.8"

until it's fixed. The problem from Leo's perspective is that 5.8 is
now the default install (at least on Windows) and that's a hurdle for
less technical users.

The PyQt list responded to my minimal example code,
https://gist.github.com/tbnorth/76191db825cc49dcca296ffb8d777047
reasonably pointing out that it's a Qt problem, not a PyQt problem.

I'll try and get feedback from the Qt people.

The question is does Leo need to code around the problem in the
interim? Certain irony in this coming up just as the themes were given
a work over.

Assuming that Qt will fix ~= reasonably quickly and it would be nice to
retain the expressiveness it provides, we could just add temporary code
tagged with "# QT_TILDE" that (a) removes tildes in the stylesheet
generated by expand_css_constants, and (b) explicitly styles elements
in cases where c.styleSheetManager.mng.* methods are used - this
wouldn't play nice with themes, but hopefully it would be short lived.

I'll start with the Qt people.

Cheers -Terry

Terry Brown

unread,
Mar 16, 2017, 9:03:50 AM3/16/17
to leo-e...@googlegroups.com
On Thu, 16 Mar 2017 07:49:03 -0500
"'Terry Brown' via leo-editor" <leo-e...@googlegroups.com> wrote:

> I'll start with the Qt people.

https://bugreports.qt.io/browse/QTBUG-59533

Edward K. Ream

unread,
Mar 16, 2017, 11:18:29 AM3/16/17
to leo-editor

​Thanks for looking into this.  I think the safest thing to do is leave the tildes in place, without changing any code. The last thing I want to do is play with speculative code just before releasing b1.

Those of us with working stylesheets can keep them without fear of breakage.  Newbies might get bitten, but we can deal with that as needed.

Edward
Reply all
Reply to author
Forward
0 new messages