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. Is it possible to fill color in bounding rectangle?
QtWS25 Last Chance

Is it possible to fill color in bounding rectangle?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.6k 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.
  • S Offline
    S Offline
    Swati777999
    wrote on 28 Dec 2021, 08:44 last edited by
    #1

    Hi All,

    I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?
    [Bounding rectangle is the rectangle in dashed line covering the outer side of a geometrical shape.]

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    J 1 Reply Last reply 28 Dec 2021, 09:01
    0
    • S Swati777999
      29 Dec 2021, 03:30

      @JKSH said in Is it possible to fill color in bounding rectangle?:

      @Swati777999 said in Is it possible to fill color in bounding rectangle?:

      So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

      That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

      Do you already have any code that performs drawing?

          QRectF rectangle(10.0, 20.0, 80.0, 60.0);
      
          // Cutomised Pen; color:black , style:dashed
          QPen dashpen;
          dashpen.setStyle(Qt::DashLine);
          dashpen.setColor(Qt::black);
      
         
          QBrush bdashrec;
          QColor orange;
          orange.setRgb(255,140,0);
          bdashrec.setStyle(Qt::SolidPattern);
          bdashrec.setColor(orange);
      
          painter.setPen(dashpen);
          painter.setBrush(bdashrec);
      
          painter.drawRect(rectangle);
      
      

      In the above code, I am drawing the rectangle, making its edge dashed, and then filling color in it
      but I wanted to just fill colors to a textbox, so tried with this one.

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 29 Dec 2021, 12:37 last edited by
      #12

      @Swati777999 said in Is it possible to fill color in bounding rectangle?:

      I wanted to just fill colors to a textbox, so tried with this one.

      ...

      Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

      ...

      It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

      I'm afraid I don't fully understand your descriptions or what you're trying to do. Can you please describe what you have already implemented, and what changes you want to make?

      If you just want to fill the background colour of a QLabel, you can apply a stylesheet to the label: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe

      For example, label->setStyleSheet("background-color: red;");

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      S 1 Reply Last reply 30 Dec 2021, 03:20
      1
      • S Swati777999
        28 Dec 2021, 08:44

        Hi All,

        I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?
        [Bounding rectangle is the rectangle in dashed line covering the outer side of a geometrical shape.]

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 28 Dec 2021, 09:01 last edited by
        #2

        @Swati777999 said in Is it possible to fill color in bounding rectangle?:

        I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?

        In general, yes.

        But you need to provide more details on how you draw the bounding rectangle.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        S 1 Reply Last reply 28 Dec 2021, 09:22
        3
        • J JKSH
          28 Dec 2021, 09:01

          @Swati777999 said in Is it possible to fill color in bounding rectangle?:

          I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?

          In general, yes.

          But you need to provide more details on how you draw the bounding rectangle.

          S Offline
          S Offline
          Swati777999
          wrote on 28 Dec 2021, 09:22 last edited by
          #3

          @JKSH said in Is it possible to fill color in bounding rectangle?:

          @Swati777999 said in Is it possible to fill color in bounding rectangle?:

          I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?

          In general, yes.

          But you need to provide more details on how you draw the bounding rectangle.

          boundingRect

          The example given in the above link:

          QRectF CircleItem::boundingRect() const
          {
              qreal penWidth = 1;
              return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
                            diameter + penWidth, diameter + penWidth);
          }
          

          So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

          “ In order to be irreplaceable, one must always be different” – Coco Chanel

          J J 2 Replies Last reply 28 Dec 2021, 09:33
          0
          • S Swati777999
            28 Dec 2021, 09:22

            @JKSH said in Is it possible to fill color in bounding rectangle?:

            @Swati777999 said in Is it possible to fill color in bounding rectangle?:

            I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?

            In general, yes.

            But you need to provide more details on how you draw the bounding rectangle.

            boundingRect

            The example given in the above link:

            QRectF CircleItem::boundingRect() const
            {
                qreal penWidth = 1;
                return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
                              diameter + penWidth, diameter + penWidth);
            }
            

            So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

            J Offline
            J Offline
            JonB
            wrote on 28 Dec 2021, 09:33 last edited by JonB
            #4

            @Swati777999
            No, because QRectF and all similars are shapes, or really just the coordinates of shapes. They do not have attributes like "fill" or "color". Those come only where you draw such a shape.

            1 Reply Last reply
            0
            • S Swati777999
              28 Dec 2021, 09:22

              @JKSH said in Is it possible to fill color in bounding rectangle?:

              @Swati777999 said in Is it possible to fill color in bounding rectangle?:

              I have a doubt. I just want to know if it is possible to fill color using a brush in a bounding rectangle?

              In general, yes.

              But you need to provide more details on how you draw the bounding rectangle.

              boundingRect

              The example given in the above link:

              QRectF CircleItem::boundingRect() const
              {
                  qreal penWidth = 1;
                  return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
                                diameter + penWidth, diameter + penWidth);
              }
              

              So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 28 Dec 2021, 13:02 last edited by JKSH
              #5

              @Swati777999 said in Is it possible to fill color in bounding rectangle?:

              So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

              That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

              Do you already have any code that performs drawing?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              S 1 Reply Last reply 29 Dec 2021, 03:30
              0
              • J JKSH
                28 Dec 2021, 13:02

                @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

                That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

                Do you already have any code that performs drawing?

                S Offline
                S Offline
                Swati777999
                wrote on 29 Dec 2021, 03:30 last edited by
                #6

                @JKSH said in Is it possible to fill color in bounding rectangle?:

                @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

                That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

                Do you already have any code that performs drawing?

                    QRectF rectangle(10.0, 20.0, 80.0, 60.0);
                
                    // Cutomised Pen; color:black , style:dashed
                    QPen dashpen;
                    dashpen.setStyle(Qt::DashLine);
                    dashpen.setColor(Qt::black);
                
                   
                    QBrush bdashrec;
                    QColor orange;
                    orange.setRgb(255,140,0);
                    bdashrec.setStyle(Qt::SolidPattern);
                    bdashrec.setColor(orange);
                
                    painter.setPen(dashpen);
                    painter.setBrush(bdashrec);
                
                    painter.drawRect(rectangle);
                
                

                In the above code, I am drawing the rectangle, making its edge dashed, and then filling color in it
                but I wanted to just fill colors to a textbox, so tried with this one.

                “ In order to be irreplaceable, one must always be different” – Coco Chanel

                J J 2 Replies Last reply 29 Dec 2021, 07:44
                0
                • S Swati777999
                  29 Dec 2021, 03:30

                  @JKSH said in Is it possible to fill color in bounding rectangle?:

                  @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                  So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

                  That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

                  Do you already have any code that performs drawing?

                      QRectF rectangle(10.0, 20.0, 80.0, 60.0);
                  
                      // Cutomised Pen; color:black , style:dashed
                      QPen dashpen;
                      dashpen.setStyle(Qt::DashLine);
                      dashpen.setColor(Qt::black);
                  
                     
                      QBrush bdashrec;
                      QColor orange;
                      orange.setRgb(255,140,0);
                      bdashrec.setStyle(Qt::SolidPattern);
                      bdashrec.setColor(orange);
                  
                      painter.setPen(dashpen);
                      painter.setBrush(bdashrec);
                  
                      painter.drawRect(rectangle);
                  
                  

                  In the above code, I am drawing the rectangle, making its edge dashed, and then filling color in it
                  but I wanted to just fill colors to a textbox, so tried with this one.

                  J Offline
                  J Offline
                  JonB
                  wrote on 29 Dec 2021, 07:44 last edited by JonB
                  #7

                  @Swati777999
                  This is the right way to do the filling --- into the QPainter. I'm not sure if you are still asking the same question as earlier? As stated, QRectF is just a rectangle's coordinates and cannot contain a color or a fill itself.

                  S 1 Reply Last reply 29 Dec 2021, 08:10
                  1
                  • J JonB
                    29 Dec 2021, 07:44

                    @Swati777999
                    This is the right way to do the filling --- into the QPainter. I'm not sure if you are still asking the same question as earlier? As stated, QRectF is just a rectangle's coordinates and cannot contain a color or a fill itself.

                    S Offline
                    S Offline
                    Swati777999
                    wrote on 29 Dec 2021, 08:10 last edited by
                    #8

                    @JonB said in Is it possible to fill color in bounding rectangle?:

                    @Swati777999
                    This is the right way to do the filling --- into the QPainter. I'm not sure if you are still asking the same question as earlier? As stated, QRectF is just a rectangle's coordinates and cannot contain a color or a fill itself.

                    Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

                    “ In order to be irreplaceable, one must always be different” – Coco Chanel

                    J 1 Reply Last reply 29 Dec 2021, 08:13
                    0
                    • S Swati777999
                      29 Dec 2021, 08:10

                      @JonB said in Is it possible to fill color in bounding rectangle?:

                      @Swati777999
                      This is the right way to do the filling --- into the QPainter. I'm not sure if you are still asking the same question as earlier? As stated, QRectF is just a rectangle's coordinates and cannot contain a color or a fill itself.

                      Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

                      J Offline
                      J Offline
                      JonB
                      wrote on 29 Dec 2021, 08:13 last edited by
                      #9

                      @Swati777999 What Qt class do you mean with "textbox"?

                      S 1 Reply Last reply 29 Dec 2021, 08:16
                      1
                      • J JonB
                        29 Dec 2021, 08:13

                        @Swati777999 What Qt class do you mean with "textbox"?

                        S Offline
                        S Offline
                        Swati777999
                        wrote on 29 Dec 2021, 08:16 last edited by Swati777999
                        #10

                        @JonB said in Is it possible to fill color in bounding rectangle?:

                        @Swati777999 What Qt class do you mean with "textbox"?

                        It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

                        “ In order to be irreplaceable, one must always be different” – Coco Chanel

                        J 1 Reply Last reply 29 Dec 2021, 08:24
                        0
                        • S Swati777999
                          29 Dec 2021, 08:16

                          @JonB said in Is it possible to fill color in bounding rectangle?:

                          @Swati777999 What Qt class do you mean with "textbox"?

                          It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

                          J Offline
                          J Offline
                          JonB
                          wrote on 29 Dec 2021, 08:24 last edited by JonB
                          #11

                          @Swati777999
                          I don't know what Windows Paint uses for what, you need to start by deciding what you are going to use in Qt for this textbox before you worry about filling it with color.

                          P.S.
                          If you are actually looking to write some Paint-type application, you might want to use QGraphicsScene for drawing and QGraphicsTextItem for your text? The Scribble Example is a Paint-type app, and you could add QGraphicsTextItems to that.

                          1 Reply Last reply
                          1
                          • S Swati777999
                            29 Dec 2021, 03:30

                            @JKSH said in Is it possible to fill color in bounding rectangle?:

                            @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                            So , in the above code, can I use paintbrush object to color the interior of boundingRect and return the edited one?

                            That code only calculates the position and dimensions of the rectangle. It does not draw the rectangle, as @JonB said.

                            Do you already have any code that performs drawing?

                                QRectF rectangle(10.0, 20.0, 80.0, 60.0);
                            
                                // Cutomised Pen; color:black , style:dashed
                                QPen dashpen;
                                dashpen.setStyle(Qt::DashLine);
                                dashpen.setColor(Qt::black);
                            
                               
                                QBrush bdashrec;
                                QColor orange;
                                orange.setRgb(255,140,0);
                                bdashrec.setStyle(Qt::SolidPattern);
                                bdashrec.setColor(orange);
                            
                                painter.setPen(dashpen);
                                painter.setBrush(bdashrec);
                            
                                painter.drawRect(rectangle);
                            
                            

                            In the above code, I am drawing the rectangle, making its edge dashed, and then filling color in it
                            but I wanted to just fill colors to a textbox, so tried with this one.

                            J Offline
                            J Offline
                            JKSH
                            Moderators
                            wrote on 29 Dec 2021, 12:37 last edited by
                            #12

                            @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                            I wanted to just fill colors to a textbox, so tried with this one.

                            ...

                            Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

                            ...

                            It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

                            I'm afraid I don't fully understand your descriptions or what you're trying to do. Can you please describe what you have already implemented, and what changes you want to make?

                            If you just want to fill the background colour of a QLabel, you can apply a stylesheet to the label: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe

                            For example, label->setStyleSheet("background-color: red;");

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            S 1 Reply Last reply 30 Dec 2021, 03:20
                            1
                            • J JKSH
                              29 Dec 2021, 12:37

                              @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                              I wanted to just fill colors to a textbox, so tried with this one.

                              ...

                              Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

                              ...

                              It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

                              I'm afraid I don't fully understand your descriptions or what you're trying to do. Can you please describe what you have already implemented, and what changes you want to make?

                              If you just want to fill the background colour of a QLabel, you can apply a stylesheet to the label: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe

                              For example, label->setStyleSheet("background-color: red;");

                              S Offline
                              S Offline
                              Swati777999
                              wrote on 30 Dec 2021, 03:20 last edited by
                              #13

                              @JKSH said in Is it possible to fill color in bounding rectangle?:

                              @Swati777999 said in Is it possible to fill color in bounding rectangle?:

                              I wanted to just fill colors to a textbox, so tried with this one.

                              ...

                              Is it possible to fill color to a textbox ? or just do as the above and then put a QLabel inside it?

                              ...

                              It's not a Qt class, in general how text-box is represented in [Untitled] By default Paint Application of Windows OS.

                              I'm afraid I don't fully understand your descriptions or what you're trying to do. Can you please describe what you have already implemented, and what changes you want to make?

                              If you just want to fill the background colour of a QLabel, you can apply a stylesheet to the label: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe

                              For example, label->setStyleSheet("background-color: red;");

                              Thanks. This works for me.

                              “ In order to be irreplaceable, one must always be different” – Coco Chanel

                              1 Reply Last reply
                              0

                              1/13

                              28 Dec 2021, 08:44

                              • Login

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