I have seen similar behavior, and I believe there is a bug filed but I forget.

Have you tried defining the default behavior as well, not just !focus, and 
!hover, but focus and hover and forground (I think its foreground)

Scott
-----Original Message-----
From: interest-bounces+scott.bloom=onshorecs....@qt-project.org 
[mailto:interest-bounces+scott.bloom=onshorecs....@qt-project.org] On Behalf Of 
Jesse Jaara
Sent: Saturday, June 20, 2015 6:12 AM
To: interest@qt-project.org
Subject: [Interest] Qt CSS :!hover seems to override defaults

I've brought up this on the IRC and the Forum sometime ago, but haven't 
received any responses as of yet.  So I'm posting this here too.

I am trying to style certain elements of my application with the CSS support.
I want the elements to look "normal" when they are active (:focus), but have 
different styling when they are inactive . For this I need to use the :!focus 
selector, but it results in the normal/default style not being applied to the 
widget when focus is gained, instead the :!focus rules still persist. Adding 
another rule :focus does override the :!focus, but I want to use the system's 
style's default instead of my own values.

This seems to be intended behavior as both Qt4 and Qt5 act in the same fashion.
What I'm looking for is to understand this behavior and preferably to find a 
way around it without having to resort to writing both :!focus and :focus rules.

The small app below demonstrates problem with Qlabels and :!hover, which has 
the same problem as the :!focus selector.


### CssTest.pro: ###################################

QT += core gui widgets
SOURCES += CssTest.cpp


### CssTest.cpp: ###################################

#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>

int main(int argc, char* argv[])
{
     QApplication app(argc, argv);

     QVBoxLayout *mainLayout = new QVBoxLayout;

     QLabel* redLabel = new QLabel("Red when mouse does not hover over this,\n"
                                   "but should turn back to default color 
(black)\n"
                                   "when mouse hovers over this text.");
     redLabel->setStyleSheet("QLabel:!hover { color: red; }");
     mainLayout->addWidget(redLabel);

     QLabel* blueLabel = new QLabel("Black when mouse does not hover over 
this,\n"
                                    "but should turn to blue when the mouse 
hovers\n"
                                    "over this text.");
     blueLabel->setStyleSheet("QLabel:hover { color: blue; }");
     mainLayout->addWidget(blueLabel);

     QWidget *w = new QWidget();
     w->setLayout(mainLayout);
     w->setWindowTitle("Css negation");

     w->show();
     return app.exec();
}

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to