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. Problem with global stylesheet

Problem with global stylesheet

Scheduled Pinned Locked Moved Solved General and Desktop
stylesheet
5 Posts 2 Posters 1.6k 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.
  • A Offline
    A Offline
    AlaaM
    wrote on last edited by AlaaM
    #1

    I'm trying to set a global stylesheet for all my buttons.
    Doing it for a specific button like the following, works:

    button->setStyleSheet(QString("QPushButton:focus {") +
                                  "outline: 0;" +
                                  "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR  + "; " +
                                  "color: #"            + BUTTON_HIGHLIGHT_TXT_COLOR + "; " +
                                  "}");
    

    But if I make it global, in the main.cpp, like this:

    qApp->setStyleSheet(QString("QPushButton:focus {") +
                                      "outline: 0;" +
                                      "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR + "; " +
                                      "color: #"            + BUTTON_HIGHLIGHT_TXT_COLOR + "; " +
                                      "}");
    

    [the following sentence was edited]
    the focused buttons get the correct font color, but always with no background (transparent?), no matter the parameter I set for the background.

    How can I fix this?
    Thanks

    raven-worxR 1 Reply Last reply
    0
    • A AlaaM

      I'm trying to set a global stylesheet for all my buttons.
      Doing it for a specific button like the following, works:

      button->setStyleSheet(QString("QPushButton:focus {") +
                                    "outline: 0;" +
                                    "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR  + "; " +
                                    "color: #"            + BUTTON_HIGHLIGHT_TXT_COLOR + "; " +
                                    "}");
      

      But if I make it global, in the main.cpp, like this:

      qApp->setStyleSheet(QString("QPushButton:focus {") +
                                        "outline: 0;" +
                                        "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR + "; " +
                                        "color: #"            + BUTTON_HIGHLIGHT_TXT_COLOR + "; " +
                                        "}");
      

      [the following sentence was edited]
      the focused buttons get the correct font color, but always with no background (transparent?), no matter the parameter I set for the background.

      How can I fix this?
      Thanks

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @AlaaM
      if possible try to set the stylesheet on your very toplevel window (mainwindow?)
      Also what Qt version are you using?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlaaM
        wrote on last edited by AlaaM
        #3

        @raven-worx
        Please see my edit.
        The font color works. It's only the highlighted background that doesn't.
        I do this in my main window.
        Qt version 5.5.1

        raven-worxR 1 Reply Last reply
        0
        • A AlaaM

          @raven-worx
          Please see my edit.
          The font color works. It's only the highlighted background that doesn't.
          I do this in my main window.
          Qt version 5.5.1

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @AlaaM
          i know, but i was thinking of some issue in style inheritance maybe.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlaaM
            wrote on last edited by AlaaM
            #5

            Answer here:
            http://stackoverflow.com/questions/35018958/global-stylesheet-isnt-fully-working

            (in short: I had a stackedWidget->setStyleSheet("background-color: white;") on the loading screen. It needed to be removed or changed to: stackedWidget->setStyleSheet("QStackedWidget { background-color: white; }");)

            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