Questions tagged [qpainter]

QPainter is a Qt class that provides low-level painting on widgets or other paint devices.

QPainter provides optimized drawing functions that can draw lines, simple shapes, pixmaps, etc. QPainter can be used with any class that inherits QPaintDevice class.

A common use of QPainter is drawing inside a widget's paintEvent(). A simple example of usage will look like this:

 void someWidget::paintEvent(QPaintEvent *)
 {
     //creating a painter
     QPainter painter(this);
     //setting the pen color
     painter.setPen(Qt::red);
     //setting the font attributes
     painter.setFont(QFont("Arial", 30));
     //rendering text.
     painter.drawText(rect(), Qt::AlignCenter, "Qt");
 }

QPainter is highly customizable which allows a great variety in drawing capabilities.

Official documentation of this class can be found here for Qt 4.8 and here for Qt 5.

665 questions
2
votes
1 answer

QPaint translation scale with mouseevent

I need to draw a shape with scaling and Qwheel event. I have tried painter.scale and painter.translate, but it does not at all effect the scaling of shape. The idea is to draw different shapes, for instance this one on the figure below, a…
Pavel.D
  • 561
  • 1
  • 15
  • 41
2
votes
1 answer

PyQt 5: QPainter returns false while rendering QGraphicsScene to a QImage

Currently I am working on a program, to display SIP-Trace log files. It is written in Python 3.7 using the PyQt 5(.11.3) module to load and operate a GUI made in QDesigner. As a main feature it parses the SIP-Trace file and displays it as a sequence…
D.Coopmann
  • 23
  • 3
2
votes
0 answers

How to fill the area under the plot?

I have the following code which should draw a sine function and fill it's internals - everything between this function and zero level. But the brush which I set up does not work. Should any additional function be called? Now I have only sine…
Skotti Bendler
  • 753
  • 1
  • 6
  • 17
2
votes
2 answers

Why does QPainter::drawPoint draw a horizontal line segment?

I'm trying to draw a 3-pixel large point with QPainter. But the following code instead draws a horizontal line with width of 3 pixels. #include #include int main() { const int w=1000, h=1000; QImage img(w, h,…
Ruslan
  • 18,162
  • 8
  • 67
  • 136
2
votes
1 answer

Warning QPainter inside paintEvent

I tried to draw some more information in QChartView so I re-implement paintEvent virtual void paintEvent(QPaintEvent *event) { QChartView::paintEvent(event); OmenChart *mchr = dynamic_cast(this->chart()); if(mchr ==…
chatzich
  • 1,083
  • 2
  • 11
  • 26
2
votes
1 answer

QPainter: drawing only the visible area of a zoomed-in image

I have a custom QQuickPaintedItem that draws whatever the user has painted onto it with the mouse. Up until now the implementation has been super simple, just drawing the entire image, even when zoomed in. I've noticed that the FPS is really slow…
Mitch
  • 23,716
  • 9
  • 83
  • 122
2
votes
1 answer

Draw arc and override boundingRect(), shape()

I have a class Edge : public QGraphicsItem, which implements drawing arrows from one Node to another (screen below). Now I need to add the ability to draw an arrow on yourself (arc). I cannot draw an arc, override boundingRect() and shape(). Code…
Kto To
  • 434
  • 5
  • 11
2
votes
0 answers

Qt how to zoom in a QWidget and its children

I have a QWidget which has 2 child QWidget, I want to zoom in it (with its children) by 200% just like we zoom in an image. (as shown in screenshot below) I know how to zoom in a single QWidget in its paintEvent() via QPainter. But I don't know how…
ricky
  • 2,058
  • 4
  • 23
  • 49
2
votes
2 answers

PyQt5: painting using events

I am new on PyQt I am working on a project on which I should implement a feature that make the user able to draw a digit using the mouse (digit recognition system). So what I want is when the mouse button is pressed the app will start to draw till…
ou2105
  • 165
  • 3
  • 10
2
votes
1 answer

qt - QPainter::rotate with non-perpendicular angles causes wiggly lines

I'm trying to draw text on a widget at an angle which is non-perpendicular, i.e. between 0 and 90. Drawing the text itself is no issue, but the resulting text is very wiggly/unevenly drawn. In the picture below, I'm drawing to lines of text at a 45…
edvardsp
  • 133
  • 8
2
votes
1 answer

Qt: Draw text in vertical direction with QPainter?

How to use QPainter.drawText() API to display text in vertical direction? The meaning of vertical direction is: A B C not like below:
ricky
  • 2,058
  • 4
  • 23
  • 49
2
votes
2 answers

Creating QGradient

Right now I am just trying to create a circle with a gradient fill: //I want the center to be at 10, 10 in the circle and the radius to be 50 pixels QRadialGradient radial(QPointF(10, 10), 50); radial.setColorAt(0, Qt::black); //I want the center to…
wrongusername
  • 18,564
  • 40
  • 130
  • 214
2
votes
1 answer

Painting through QDirectPainter

Can anyone suggest me in detail how to use QDirectPainter class to paint a widget directly on frame buffer. I would be more helpful if you provide me a working example.
Vivek GUpta
2
votes
2 answers

How to create a simple Image (QImage) with text and colors in QT and save it as file

I have to create some Images as placeholder for articles which have no own images / pictures. I already realized this in python, but i want to write the code in a qt app again. The python code is working and it looks like this: def…
Teddy2000
  • 21
  • 1
  • 2
2
votes
1 answer

How to remove Ghost Lines drawn in qgraphicsview

I am trying to make a simple program in which I have added a qgraphics scene and in this I have added a QGraphicsRectItem. I have implemented mouse press event, paint event, bounding rect. Now I have drawn a point on one side of rectangle because…
sk110
  • 77
  • 2
  • 9