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 style each custom button in global QMessageBox styleSheet ?
Forum Updated to NodeBB v4.3 + New Features

How to style each custom button in global QMessageBox styleSheet ?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • LematL Offline
    LematL Offline
    Lemat
    wrote on last edited by Lemat
    #1

    I want to style each custom button of my QMessageBox in one stylesheet file without using setStyleSheet() for each button.

    my QMessageBox style sheet:

    QMessageBox
    {
      background-color:#dedede;
    }
    
    QLabel
    {
      color:#444;
    }
    
    QPushButton
    {
    border:2px solid #0076a3;
    border-radius:5px;
    color:#fff;
    background-color:#0898d8;
    padding:2px 25px;
    }
    QPushButton:hover:!pressed
    {
    border:1px solid #0076a3;
    }
    QPushButton:pressed
    {
    background-color:transparent;
    border:2px solid #444;
    color:#444;
    }
    

    and i want style like:

    QMessageBox
    {
      background-color:#dedede;
    }
    
    QLabel
    {
      color:#444;
    }
    
    QPushButton#oui
    {
    border:2px solid #0076a3;
    border-radius:5px;
    color:#fff;
    background-color:#0898d8;
    padding:2px 25px;
    }
    QPushButton#oui:hover:!pressed
    {
    border:1px solid #0076a3;
    }
    QPushButton#oui:pressed
    {
    background-color:transparent;
    border:2px solid #444;
    color:#444;
    }
    
    QPushButton#non
    {
      border:1px solid #444;
      border-radius:5px;
      color:#444;
      padding:2px 25px;
      background:transparent;
     }
     QPushButton#non:hover:!pressed
     {
        border:none;
        background-color:#0898d8;
        color:#fff;
     }
     QPushButton#non:pressed
     {
       border:2px solid #0076a3;
       color:#fff;
       background-color:#0898d8;
     }
    

    QPushButton#oui and QPushButton#non are custom buttons added to QMessageBox.

    Time to elevate.

    1 Reply Last reply
    0
    • LematL Offline
      LematL Offline
      Lemat
      wrote on last edited by Lemat
      #4

      @Christian-Ehrlicher,
      it work well now as expected after i created my own dialog inherit QDialog and used setStyleSheet for the whole personal dialog. thank you for your help.

      Time to elevate.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Then set the stylesheet as global style sheet in QApplication

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • LematL Offline
          LematL Offline
          Lemat
          wrote on last edited by
          #3

          it seem work...

          Why doesn't it work directly on QMessageBox setStyleSheet ()?

          Time to elevate.

          1 Reply Last reply
          0
          • LematL Offline
            LematL Offline
            Lemat
            wrote on last edited by Lemat
            #4

            @Christian-Ehrlicher,
            it work well now as expected after i created my own dialog inherit QDialog and used setStyleSheet for the whole personal dialog. thank you for your help.

            Time to elevate.

            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