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?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to fill color in bounding rectangle?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.7k 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.
  • JKSHJ JKSH

    @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.

    Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on 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

    JonBJ JKSHJ 2 Replies Last reply
    0
    • Swati777999S Swati777999

      @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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      • Swati777999S Swati777999

        @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?

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on 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

        Swati777999S 1 Reply Last reply
        0
        • JKSHJ JKSH

          @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?

          Swati777999S Offline
          Swati777999S Offline
          Swati777999
          wrote on 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

          JonBJ JKSHJ 2 Replies Last reply
          0
          • Swati777999S Swati777999

            @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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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.

            Swati777999S 1 Reply Last reply
            1
            • JonBJ JonB

              @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.

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on 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

              JonBJ 1 Reply Last reply
              0
              • Swati777999S Swati777999

                @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?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #9

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

                Swati777999S 1 Reply Last reply
                1
                • JonBJ JonB

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

                  Swati777999S Offline
                  Swati777999S Offline
                  Swati777999
                  wrote on 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

                  JonBJ 1 Reply Last reply
                  0
                  • Swati777999S Swati777999

                    @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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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
                    • Swati777999S Swati777999

                      @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.

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on 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

                      Swati777999S 1 Reply Last reply
                      1
                      • JKSHJ JKSH

                        @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;");

                        Swati777999S Offline
                        Swati777999S Offline
                        Swati777999
                        wrote on 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

                        • Login

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