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. How to set Stylesheet for an application?
Qt 6.11 is out! See what's new in the release blog

How to set Stylesheet for an application?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    Hi!

    I set a stylesheet to an application. I defined a general look for QPushButton and some styles for QPushbutton#name. The problem is...if i set a generic style for QPushButton, the style for QPushbutton#name is not set. The QPushbutton#name looks exactly like the general style for QPushButton. What is the error?

    Here's the style:

    @MainWidget {
    min-width: 1024px;
    min-height: 768px;
    border: 1px solid rgba(0, 0, 0, 255);
    background-image: url(styles/default/images/bgmain.jpg);
    }

    BackgroundPanel {
    background-image: url(styles/default/images/head_tile.bmp);
    min-height: 60px;
    max-height: 60px;
    margin: 0px;
    spacing: 0px;
    }

    QStatusBar {
    background-image: url(styles/default/images/head_tile.bmp);
    min-height: 30px;
    max-height: 30px;
    margin-right: 0px;
    margin-left: 0px;
    margin-bottom: 0px;
    }

    MainCentralWidget {

    }

    QPushButton {
    color: white;
    font: bold 10pt;
    border-image: url(styles/default/images/button_normal.png) 4 4 4 4;
    border-width: 4px 4px 4px 4px;
    }

    QPushButton:hover {
    border-image: url(styles/default/images/button_hover.png);
    }

    QPushButton:pressed {
    border-image: url(styles/default/images/button_active.png);
    }

    /QPushButton:active {
    color: white;
    font: bold 10pt;
    /background-color : red;/
    border-image: url(styles/default/images/button_active.png) 4;
    }
    /

    QPushButton#closeButton {
    border-image: url(styles/default/images/but_close_normal.png) 0;
    border-width: 0px;
    max-width: 50px;
    max-height: 21px;
    min-width: 50px;
    min-height: 21px;
    margin-top: 0px;
    }

    QPushButton#closeButton:hover {
    border-image: url(styles/default/images/but_close_hover.png);
    }

    QPushButton#maximizeButton {
    border-image: url(styles/default/images/but_close_normal.png) 0;
    border-width: 0px;
    max-width: 50px;
    max-height: 21px;
    min-width: 50px;
    min-height: 21px;
    margin-top: 0px;
    }

    QPushButton#maximizeButton:hover {
    border-image: url(styles/default/images/but_maximize_hover.png);
    }

    QPushButton#maximizeButton:disabled {
    border-image: url(styles/default/images/but_maximize_disabled.png);
    }

    QPushButton#minimizeButton {
    border-image: url(styles/default/images/but_minimize.png);
    border-width: 0px
    max-width: 27px;
    max-height: 21px;
    }

    QPushButton#minimizeButton:hover {
    border-image: url(styles/default/images/but_minimize_hover.png);
    }

    QLabel#logoLabel {
    background-image: url(styles/default/images/logo.png);
    min-height: 60px;
    max-height: 60px;
    min-width: 172px;
    max-width: 172px;
    background-color: #FF0000;

    }
    @

    In the constructor i set the objectname via setObjectName("name"). But it looks like the general QPushButton style and not with the #name in stylesheet?

    Any ideas?

    Thank you very much!

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      it seems the problem is this:
      @
      /QPushButton:active {
      color: white;
      font: bold 10pt;
      /background-color : red;/
      border-image: url(styles/default/images/button_active.png) 4;
      }
      /
      @
      which will generate a parser error. So the parser will stop there and not apply the lines after.
      The code highlighting here shows it clearly ;)

      --- 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
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        Uuumm...yes! Thank you. Sometimes it's better another person reads the code ;-)

        Thank you very much.

        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