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. Applying StyleSheet to Custom Window
Forum Updated to NodeBB v4.3 + New Features

Applying StyleSheet to Custom Window

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 9.6k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #2

    Styling a custom widget through style sheets is not supported. Sorry.

    Edit:
    Well, let me specify that a bit: custom drawn custom widgets can not be styled using qss. You can use qss to style custom widgets that are just compositions of existing Qt widgets.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Thibaut
      wrote on last edited by
      #3

      By custom drawn widget, you do mean widgets inherited from Qwidget, right ?

      Are you aware of any plan to implement this in a next version ?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #4

        Me? No, not me. I don't work for Nokia :-)

        What I mean by custom drawn, are widgets that are based directly on QWidget and where you implement paintEvent() do do your own painting yourself.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #5

          If you just derive from QWidget and need that one styled, you have to do some stuff :-)

          @
          void TitiWidget::paintEvent(QPaintEvent* /p_pEvent/)
          {
          QStyleOption opt;
          opt.init(this);
          QStylePainter p(this);
          p.drawPrimitive(QStyle::PE_Widget, opt);
          }
          @

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deimos
            wrote on last edited by
            #6

            why not in the constructor of TitiWidget put this ?

            @
            setStyleSheet(
            "border: 2px solid green;"
            "border-radius: 20px;"
            "padding: 2px;"
            "background-color: rgb(85, 85, 255);"
            );@

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #7

              [quote author="marcoB" date="1305200019"]why not in the constructor of TitiWidget put this ?

              @
              setStyleSheet(
              "border: 2px solid green;"
              "border-radius: 20px;"
              "padding: 2px;"
              "background-color: rgb(85, 85, 255);"
              );@
              [/quote]

              Because it all depends on how TitiWidget is implemented if this is going to work or not.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #8

                It only works if you overwrite the paint event.
                Otherwise nothing happens.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Thibaut
                  wrote on last edited by
                  #9

                  Thanks a lot for your answers.

                  The
                  @
                  void TitiWidget::paintEvent(QPaintEvent* /p_pEvent/)
                  {
                  QStyleOption opt;
                  opt.init(this);
                  QStylePainter p(this);
                  p.drawPrimitive(QStyle::PE_Widget, opt);
                  }
                  @

                  trick works just fine. And it's actually in Qt's documentation. Shame on me.

                  Edit: please use code tags (@) before and after your code section; Andre

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #10

                    Nice trick to get at least the basic style sheet stuff painted correctly, but I still don't see a way to get where you can draw, let alone a way to style what you draw yourself using that style sheet...

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #11

                      That does not work at all. If you have a custom drawn widget, it can't be styled. Only if you do some basic style sheet stuff and paint on it later...

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      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