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. Customizing QMainWindow by style sheet

Customizing QMainWindow by style sheet

Scheduled Pinned Locked Moved Solved General and Desktop
stylesheetqt5.8cssqmainwindow
5 Posts 3 Posters 13.7k 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.
  • E Offline
    E Offline
    eDeviser
    wrote on last edited by
    #1

    Hello, I am very new to QT and I tried to use a style sheet to adapt my QMainWindow's behavior. I would like to change its size, position or style if the mouse courser hovers over it.

    I just created a simple Qt-Widgets-Application with one QMainWindow which has the name MyWindow.
    In the designer I selected MyWindow and clicked to 'Style sheet edit' within the context menu.

    A little editor opens and I inserted the fallowing example from here:

    QMainWindow::separator {
        background: yellow;
        width: 10px; /* when vertical */
        height: 10px; /* when horizontal */
    }
    
    QMainWindow::separator:hover {
        background: red;
    }
    

    According to the style sheet I suggest that MyWindow would have a red background when the mouse courser points to it. Otherwise the background would be yellow.

    Nevertheless really nothing happens if the mouse course points to MyWindow at runtime.

    How to use this example to Customizing QMainWindow?

    m.sueM 1 Reply Last reply
    0
    • E eDeviser

      Hello, I am very new to QT and I tried to use a style sheet to adapt my QMainWindow's behavior. I would like to change its size, position or style if the mouse courser hovers over it.

      I just created a simple Qt-Widgets-Application with one QMainWindow which has the name MyWindow.
      In the designer I selected MyWindow and clicked to 'Style sheet edit' within the context menu.

      A little editor opens and I inserted the fallowing example from here:

      QMainWindow::separator {
          background: yellow;
          width: 10px; /* when vertical */
          height: 10px; /* when horizontal */
      }
      
      QMainWindow::separator:hover {
          background: red;
      }
      

      According to the style sheet I suggest that MyWindow would have a red background when the mouse courser points to it. Otherwise the background would be yellow.

      Nevertheless really nothing happens if the mouse course points to MyWindow at runtime.

      How to use this example to Customizing QMainWindow?

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi @eDeviser

      you will have to do it with the object that you set as central widget.

      -Michael.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mostefa
        wrote on last edited by
        #3

        Hi @eDeviser

        As @m-sue told youneed to have a centralWidget , (of QWidget type for example)

        Your stylesheet will be then:

        QWidget {
        background: yellow;
        width: 10px; /* when vertical /
        height: 10px; /
        when horizontal */
        }

        QWidget:hover {
        background: red;
        }

        Hope this can help you,

        Best regards!

        1 Reply Last reply
        0
        • E Offline
          E Offline
          eDeviser
          wrote on last edited by
          #4

          Yes, this helps!

          I see the QMainWindow holds a QWidget which is set as cetralWidget. So It would be necessary to set the QMainWindow as centralWidget or to apply my css for the QWidget.

          0_1501135343432_3169fb05-5a7c-4700-9cd0-ae074842feab-image.png

          Thank you for this hint.

          M 1 Reply Last reply
          0
          • E eDeviser

            Yes, this helps!

            I see the QMainWindow holds a QWidget which is set as cetralWidget. So It would be necessary to set the QMainWindow as centralWidget or to apply my css for the QWidget.

            0_1501135343432_3169fb05-5a7c-4700-9cd0-ae074842feab-image.png

            Thank you for this hint.

            M Offline
            M Offline
            mostefa
            wrote on last edited by
            #5

            @eDeviser said in Customizing QMainWindow by style sheet:

            Yes, this helps!

            I see the QMainWindow holds a QWidget which is set as cetralWidget. So It would be necessary to set the QMainWindow as centralWidget or to apply my css for the QWidget.

            0_1501135343432_3169fb05-5a7c-4700-9cd0-ae074842feab-image.png

            Thank you for this hint.

            You have to apply your css in your qwidget !

            Your css should be :

            centralWidget {
            background: yellow;
            width: 10px; /* when vertical /
            height: 10px; / when horizontal */
            }

            centralWidget:hover {
            background: red;
            }

            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