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. Qt CSS :!hover seems to override defaults

Qt CSS :!hover seems to override defaults

Scheduled Pinned Locked Moved General and Desktop
stylesstylingcsshovernegationstylesheet
1 Posts 1 Posters 1.5k 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.
  • H Offline
    H Offline
    Huulivoide
    wrote on last edited by Huulivoide
    #1

    Qt version: 5.4.2

    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.

    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();
    }
    
    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