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. QPainter::setClipping(false) is not working(Qt 4.8)
QtWS25 Last Chance

QPainter::setClipping(false) is not working(Qt 4.8)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwidgetqpainterclippingpaintevent
14 Posts 4 Posters 2.8k 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.
  • A Offline
    A Offline
    arju.ach
    wrote on last edited by
    #1

    Hi ,

    I am trying to a draw text below QPushButton(out side bound of button) whenever it gets focused. For this I have subclassed QPushButton and I am drawing text using QPainter drawText method inside over-riden paintEvent method of QPushButton. And before drawing I am setting QPainter::setClipping(false) to enable text drawing out side button's bounds. But some how QPainter::setClipping(false) is not working and text is not getting drawn outside the button bounds. Can any one please help me with this? Thanks in advance.

    Thanks & Regards,
    Arjun

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

      Hi,

      Do you mean you want to draw on the widget containing the push button from within the button ?

      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
      0
      • A Offline
        A Offline
        arju.ach
        wrote on last edited by
        #3

        Yes. First I checked whether there is a way to disable clipping on widget directly in which case I could have contained a button and label inside a widget. But I dint find a way to do it directly. So I tried subclassing QPushButton and tried to draw text from inside paint event outside the bounds of button with clipping disabled using QPainter methods..

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by dheerendra
          #4

          Is there a sample to show what you are doing ? Also if you show some image on what you wanted to achieve will also help.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          A 1 Reply Last reply
          0
          • dheerendraD dheerendra

            Is there a sample to show what you are doing ? Also if you show some image on what you wanted to achieve will also help.

            A Offline
            A Offline
            arju.ach
            wrote on last edited by
            #5

            @dheerendra 0_1544862322913_Screen Shot 2018-12-15 at 1.54.34 PM.png
            Thanks.

            I am trying to do like attached image. At a time only one button can be focused and when it gets focused I want to show button's horizontal centre aligned action description below the button. The issue is description can come under another button also and can grow out of buttons bounds.

            aha_1980A 1 Reply Last reply
            0
            • A arju.ach

              @dheerendra 0_1544862322913_Screen Shot 2018-12-15 at 1.54.34 PM.png
              Thanks.

              I am trying to do like attached image. At a time only one button can be focused and when it gets focused I want to show button's horizontal centre aligned action description below the button. The issue is description can come under another button also and can grow out of buttons bounds.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #6

              @arju.ach Why don't you just use a QLabel in combination with a QVBoxLayout?

              Or arrange all widgets in a QGridLayout?

              Qt has to stay free or it will die.

              A 1 Reply Last reply
              1
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                You are slightly over engineering the task. You don't need the painting or subclassing. As @aha_1980 said, it can be managed with simple visual elements like QLabel & Layouts.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

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

                  Out of curiosity, why it there a need for such a description ?

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

                  A 1 Reply Last reply
                  0
                  • aha_1980A aha_1980

                    @arju.ach Why don't you just use a QLabel in combination with a QVBoxLayout?

                    Or arrange all widgets in a QGridLayout?

                    A Offline
                    A Offline
                    arju.ach
                    wrote on last edited by
                    #9

                    @aha_1980 said in QPainter::setClipping(false) is not working(Qt 4.8):

                    @arju.ach Why don't you just use a QLabel in combination with a QVBoxLayout?

                    Can you please explain how to do it?

                    1 Reply Last reply
                    0
                    • dheerendraD dheerendra

                      You are slightly over engineering the task. You don't need the painting or subclassing. As @aha_1980 said, it can be managed with simple visual elements like QLabel & Layouts.

                      A Offline
                      A Offline
                      arju.ach
                      wrote on last edited by
                      #10

                      @dheerendra
                      Can you please explain how to do it? Also please note that all the buttons will be dynamic based on some backend response and also spacing between them can change in some scenarios. I tried even this. https://stackoverflow.com/questions/53785115/qpainter-ignores-clipping-inside-paintevent/53785991?noredirect=1#comment94442586_53785991

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Out of curiosity, why it there a need for such a description ?

                        A Offline
                        A Offline
                        arju.ach
                        wrote on last edited by
                        #11

                        @SGaist It is the UX requirement , easiest thing was to put both icon and description inside button.

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

                          You could have simple QLabel that you would move as need and from which you update the text when the buttons get their focus changed.

                          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
                          0
                          • A Offline
                            A Offline
                            arju.ach
                            wrote on last edited by arju.ach
                            #13

                            @SGaist Yes I tried that only. But first time when we switch into the view it doesn't appear properly. Btw button is inside horizontal layout. We kind of wanted to make it reusable since we have that in many places, so I subclassed QPushButton.

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

                              You can make a "container widget" that will handle the showing of the label properly.

                              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
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved