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. border-color property does not work on custom stylesheet
Forum Updated to NodeBB v4.3 + New Features

border-color property does not work on custom stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 200 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    From here I learn I can customize a QLineEdit (but I guess any widget that supports the box model) using the border-color property.

    In my Qt 6.8.2 desktop application I have this code:

    if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
    {
        w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
    }
    

    The goal is to apply the stylesheet to all widgets at once.
    Actually the gridline-color is honored, but the border-color does not:

    ae3cc63d-4794-45c2-ab49-708d34b10abc-image.png

    As you can see the grid of the QTableView is grady (instead of the default black) but the QLineEdit border is still black.
    Is my stylesheet wrong?

    Here the content of my main.cpp:

    #include "mainwindow.h"
    
    #include <QStyleHints>
    #include <QApplication>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QCoreApplication::setApplicationVersion("v0.1");
    
        MainWindow w;
        // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either
        if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
        {
            w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
        }
    
        w.show();
        return a.exec();
    }
    
    jsulmJ B 2 Replies Last reply
    0
    • M Mark81

      From here I learn I can customize a QLineEdit (but I guess any widget that supports the box model) using the border-color property.

      In my Qt 6.8.2 desktop application I have this code:

      if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
      {
          w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
      }
      

      The goal is to apply the stylesheet to all widgets at once.
      Actually the gridline-color is honored, but the border-color does not:

      ae3cc63d-4794-45c2-ab49-708d34b10abc-image.png

      As you can see the grid of the QTableView is grady (instead of the default black) but the QLineEdit border is still black.
      Is my stylesheet wrong?

      Here the content of my main.cpp:

      #include "mainwindow.h"
      
      #include <QStyleHints>
      #include <QApplication>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QCoreApplication::setApplicationVersion("v0.1");
      
          MainWindow w;
          // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either
          if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
          {
              w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
          }
      
          w.show();
          return a.exec();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 What is w in your code? Are you sure you apply that stylesheet on QLineEdit?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Mark81

        From here I learn I can customize a QLineEdit (but I guess any widget that supports the box model) using the border-color property.

        In my Qt 6.8.2 desktop application I have this code:

        if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
        {
            w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
        }
        

        The goal is to apply the stylesheet to all widgets at once.
        Actually the gridline-color is honored, but the border-color does not:

        ae3cc63d-4794-45c2-ab49-708d34b10abc-image.png

        As you can see the grid of the QTableView is grady (instead of the default black) but the QLineEdit border is still black.
        Is my stylesheet wrong?

        Here the content of my main.cpp:

        #include "mainwindow.h"
        
        #include <QStyleHints>
        #include <QApplication>
        #include <QDebug>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            QCoreApplication::setApplicationVersion("v0.1");
        
            MainWindow w;
            // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either
            if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
            {
                w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }");
            }
        
            w.show();
            return a.exec();
        }
        
        B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #3

        @Mark81 You need to write the full border style:

            border-width: 1px;
            border-style: solid;
            border-color: red;
        

        or

        border: 1px solid red
        
        M 1 Reply Last reply
        2
        • B Bonnie

          @Mark81 You need to write the full border style:

              border-width: 1px;
              border-style: solid;
              border-color: red;
          

          or

          border: 1px solid red
          
          M Offline
          M Offline
          Mark81
          wrote on last edited by
          #4

          @Bonnie said in border-color property does not work on custom stylesheet:

          @Mark81 You need to write the full border style:

          You're right. I didn't understand this from the docs!

          Out of curiosity, to test the Light style I added this line:

          QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light);
          

          but the theme is still dark (as per my system settings).
          The docs (here) state I can set an explicit color scheme. Is there anything else I should set?

          I'm aware it is slightly offtopic, but it is useful to test the stylesheet in different scenarios.

          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