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. QLabel pixmap not affected by CSS property: border
Forum Updated to NodeBB v4.3 + New Features

QLabel pixmap not affected by CSS property: border

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 1.6k Views 2 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.
  • D Offline
    D Offline
    diniamo
    wrote on last edited by
    #1

    As I said in the subject when I set a pixmap for my it doesn't get affected by the CSS property border.

    Expected result:
    sm-pixel-art-creator_JhqnogAZys-edited.png
    Actual result:
    sm-pixel-art-creator_JhqnogAZys.png

    (This is photoshopped, but I think you got the idea)

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

      What do you actually do? I mean - how should we know what's wrong when you don't tell us what you're trying to achieve with what code...
      Also note that Qt doesn't support use CSS for styling but QSS which is only a minor subset of CSS.

      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
      0
      • D Offline
        D Offline
        diniamo
        wrote on last edited by diniamo
        #3

        'QSS' code of the label:

        background-color: rgb(62, 62, 62);
        border: 1px solid rgb(255, 145, 0);
        border-radius: 26px;
        

        Without Pixmap:
        13688044-2e89-443c-bc8c-6b90f21083a5-image.png

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

          The frame is painted before the pixmap so you have no other chance then doing the painting by yourself.

          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
          • D Offline
            D Offline
            diniamo
            wrote on last edited by
            #5

            How exactly would I do that?
            I can probably figure out most of it, I just need a starting point.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Create a subclass of QLabel and overload the paintEvent method. There you call the base class implementation and after that, do your custom drawing on top of your image.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • D Offline
                D Offline
                diniamo
                wrote on last edited by diniamo
                #7

                That's what I figure, but can I use that class in qt designer after?
                Also I don't want to draw on top of the image, I want to draw the image with a bevel effect.

                Christian EhrlicherC 1 Reply Last reply
                0
                • D diniamo

                  That's what I figure, but can I use that class in qt designer after?
                  Also I don't want to draw on top of the image, I want to draw the image with a bevel effect.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @diniamo said in QLabel pixmap not affected by CSS property: border:

                  That's what I figure, but can I use that class in qt designer after?

                  See https://doc.qt.io/qt-5/designer-using-custom-widgets.html

                  Also I don't want to draw on top of the image, I want to draw the image with a bevel effect.

                  Since you do the drawing on your own then you can draw whatever you want.

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

                  D 1 Reply Last reply
                  1
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #9

                    Try to add padding to see if it helps.
                    padding is added between border and contents.
                    https://doc.qt.io/archives/qt-4.8/stylesheet-customizing.html

                    D 1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD

                      Try to add padding to see if it helps.
                      padding is added between border and contents.
                      https://doc.qt.io/archives/qt-4.8/stylesheet-customizing.html

                      D Offline
                      D Offline
                      diniamo
                      wrote on last edited by
                      #10

                      @JoeCFD that just makes it ugly, the image becomes smaller, won't work in my case.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @diniamo said in QLabel pixmap not affected by CSS property: border:

                        That's what I figure, but can I use that class in qt designer after?

                        See https://doc.qt.io/qt-5/designer-using-custom-widgets.html

                        Also I don't want to draw on top of the image, I want to draw the image with a bevel effect.

                        Since you do the drawing on your own then you can draw whatever you want.

                        D Offline
                        D Offline
                        diniamo
                        wrote on last edited by diniamo
                        #11

                        @Christian-Ehrlicher Do I have access to the standard label paint event, to look at as an example? As well as qframe's probably.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          diniamo
                          wrote on last edited by
                          #12

                          Hm, no, it doesn't seem like I can just reimplement the paint event here... :/

                          M 1 Reply Last reply
                          0
                          • D diniamo

                            Hm, no, it doesn't seem like I can just reimplement the paint event here... :/

                            M Offline
                            M Offline
                            mchinand
                            wrote on last edited by
                            #13

                            Can you use a combination of drawImage and clipPath in a custom PaintEvent to achieve what you want?

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              diniamo
                              wrote on last edited by
                              #14

                              Sure, but I can't just call super().whatever to draw the rest because that the draws the image itself as well..

                              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