Is it possible to fill color in bounding rectangle?
-
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.] -
@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;");
-
@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.
-
@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.
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?
-
@Swati777999
No, becauseQRectF
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. -
@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?
-
@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. -
@Swati777999
This is the right way to do the filling --- into theQPainter
. 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. -
@JonB said in Is it possible to fill color in bounding rectangle?:
@Swati777999
This is the right way to do the filling --- into theQPainter
. 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?
-
@Swati777999 What Qt class do you mean with "textbox"?
-
@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.
-
@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 useQGraphicsScene
for drawing andQGraphicsTextItem
for your text? The Scribble Example is a Paint-type app, and you could addQGraphicsTextItem
s to that. -
@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;");
-
@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.