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. Using a stylish gradient in a QGraphicsItem
QtWS25 Last Chance

Using a stylish gradient in a QGraphicsItem

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 1.2k 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.
  • AndyBriceA Offline
    AndyBriceA Offline
    AndyBrice
    wrote on last edited by
    #1

    I am using a QBrush with a QLinearGradient to paint the background of a QGraphicsItem.
    0_1561466423906_gradient.png
    It looks ok, but a bit flat. I want it to look more 3 dimensional, which means a non-linear gradient. Something more like this.
    0_1561466778626_gradient2.png
    Has anyone done this? How did you do it?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Im not 100% sure what you ask, but try use the editor and see what you can build.
      its quite handy.
      alt text

      1 Reply Last reply
      2
      • AndyBriceA Offline
        AndyBriceA Offline
        AndyBrice
        wrote on last edited by
        #3

        Is that part of the designer in QtCreator? Or is that a QML thing?

        mrjjM 1 Reply Last reply
        0
        • AndyBriceA AndyBrice

          Is that part of the designer in QtCreator? Or is that a QML thing?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AndyBrice
          hi
          its in Designer
          Right click any widget, Change style sheet, Add Gradient (choose some color)
          then Edit or New to open editor.

          1 Reply Last reply
          1
          • AndyBriceA Offline
            AndyBriceA Offline
            AndyBrice
            wrote on last edited by AndyBrice
            #5

            Thanks. I'm thinking perhaps I need a radial gradient.

            mrjjM 1 Reply Last reply
            0
            • AndyBriceA AndyBrice

              Thanks. I'm thinking perhaps I need a radial gradient.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AndyBrice
              You can drag the handles to make it turn any way you want.

              1 Reply Last reply
              0
              • AndyBriceA Offline
                AndyBriceA Offline
                AndyBrice
                wrote on last edited by
                #7

                Thanks.

                On investigating a bit more it looks like the nice bitmaps above are a linear gradient, but with multiple 'stops' and some dithering. Might be quite difficult to do with QPainter calls. Perhaps I need to take a small vertical slice and tile that across the rectangle.

                mrjjM 1 Reply Last reply
                0
                • AndyBriceA AndyBrice

                  Thanks.

                  On investigating a bit more it looks like the nice bitmaps above are a linear gradient, but with multiple 'stops' and some dithering. Might be quite difficult to do with QPainter calls. Perhaps I need to take a small vertical slice and tile that across the rectangle.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @AndyBrice
                  Hi
                  Im not sure about what part you want to draw with gradient as
                  for me- the difference between the pic 1n pic 2 is the use of
                  drop shadow on the buttons so they are not so flat looking.

                  1 Reply Last reply
                  0
                  • AndyBriceA Offline
                    AndyBriceA Offline
                    AndyBrice
                    wrote on last edited by
                    #9

                    I think it is the dithering more than the drop shadow that makes it look pretty. But I'm not a graphic designer, so I am not 100% sure. ;0)

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi
                      The subtle drop shadow also helps.
                      alt text

                      if we compare to flat version

                      alt text

                      However, the gradients were more simple than i though
                      alt text

                      in the white box, is is just linear between the colors shown. and it really looks the same. (IMHO)

                      AndyBriceA 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        Hi
                        The subtle drop shadow also helps.
                        alt text

                        if we compare to flat version

                        alt text

                        However, the gradients were more simple than i though
                        alt text

                        in the white box, is is just linear between the colors shown. and it really looks the same. (IMHO)

                        AndyBriceA Offline
                        AndyBriceA Offline
                        AndyBrice
                        wrote on last edited by
                        #11

                        @mrjj Yes, it is just a simple linear gradient. I'm surprised. Thanks.

                        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