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

How to paint on top of QListWidget in eventfilter in PyQt4/PySide?

I tried this on QLable and it works, I do not want to subclass the widget, because they are defined in .ui files, and I just need to do simple modification so I want to avoid delegate. If I put my code in paintEvent it works, but why I can not put…
Shuman
  • 3,914
  • 8
  • 42
  • 65
2
votes
2 answers

Coordinate scaling causes too large font sizes in QPainter::drawText

I'm working on simple 2D visualization module for MD simulation code. What I'm trying to do is drawing positions of simulated molecules using: myPainter.drawEllipse(myQPoint,myRx,myRy) And that part works pretty good on my visualization widget.…
Moomin
  • 1,846
  • 5
  • 29
  • 47
2
votes
0 answers

Printing really huge image on plotter using QPrinter

I have to print on plotter world map with a lot of vector data on it from Qt based app. Plotter has 80 GB hard drive, to print high resolution images. All data is loaded in QGraphicsScene. QGraphicsScene *scene; ..... QPrinter *printer = new…
Ujifman
  • 21
  • 3
2
votes
2 answers

Draw a line with QPainter using QGraphicsView subclass

Question: I can't make the GraphicsView's paintEvent be called or in other words I don't know how to make QPainter work altogether. I'm using qtcreator's designer to place a QGraphicsView into the main window. I sub-classed QGraphicsView (class…
Daniel Katz
  • 2,271
  • 3
  • 25
  • 27
2
votes
1 answer

Qt 5.5 draw filled pie

The image below shows the grey pie, I would like to draw this using Qt 5.5 X increases left to right Y increases top to bottom I have a start angle and an end angle which represents to the top and bottom of the arc, I am calculating the arc angle…
SPlatten
  • 5,334
  • 11
  • 57
  • 128
2
votes
1 answer

I cannot draw a simple line in qt

I'm trying to drawing a simple line using a dialog but when I compile my code nothing happens, I have the dialog without nothing, please any body could explain me what is happening? Below my code: #include "dialog.h" #include "ui_dialog.h" #include…
2
votes
1 answer

QPainter drawImage becomes very pixelated

I use QPainter and the function drawImage to draw an airplane on a map. The image and redrawn each time the position of the airplane changes. The problem is, after some time, the image becomes extremely pixelated. I have tried to use a high quality…
bull
  • 25
  • 5
2
votes
2 answers

Is it possible to set global QPainter default render hints?

When a QPainter is created, it has some default render hints. Some widgets override them when painting themselves. Is it possible to override these defaults and disable the per-widget overrides for the entire application? I'd like to override the…
synacker
  • 1,722
  • 13
  • 32
2
votes
1 answer

Qt, Set an exclusive clipping region

In Qt you can set a clipping region for a QPainter with modes ReplaceClip or IntesectClip but I miss an "ExcludeClip". How would you draw (filling) a "donut" (a circle with a transparent hole) without reverting to intermediate QPixmaps?
tru7
  • 6,348
  • 5
  • 35
  • 59
2
votes
1 answer

Drawing polylines with specific angles in QT

is it possible to add a specific angles to polyline in QT? i draw a polyline with: QPointF points[3] = { QPointF(x,y), QPointF(x2,y2}; QPointF(x3,y3}; painter.drawPolyline(points, 3); I need a polyline with an arrow at…
user3676560
  • 151
  • 2
  • 15
2
votes
0 answers

Qt Painting Optimization with Cached Pixmap

I was wondering what the most efficient way to paint a mostly-static QWidget with several overplayed, semi-transparent gradients would be. I'm considering two options: Just place all the painting code in the paintEvent function like usual. Paint…
K. Barresi
  • 1,275
  • 1
  • 21
  • 46
2
votes
1 answer

Qt QPainter error when rotating an ellipse using horizontalSlider

I have to create a simple box which rotates an ellipse and some text depending upon value from horizontalSlider/spinBox. The widget has to be resizable, And size of the ellipse has to change depending upon that. For now only the ellipse is being…
Khushman Patel
  • 1,066
  • 2
  • 13
  • 23
2
votes
1 answer

Animated text with QPainter

Is it possible to draw an animated text with QPainter? I only want to change color of text periodically. If possible how to achieve?
onurozcelik
  • 1,214
  • 3
  • 21
  • 44
2
votes
1 answer

How to apply alpha channel on drawPixmap with SourceOver

I am trying to understand the different composition modes of QPainter, but the alpha channel still obscure for me. Lets see the following example: QPainter…
Adrian Maire
  • 14,354
  • 9
  • 45
  • 85
2
votes
2 answers

Refreshing MainWindow in a loop to simulate a move of QWidget in QT

I am new in QT and my problem is to refresh the page in a loop to make a move on QWidget. In detail, I have too many points (It is the path which will be followed by an ellipse and they will be drawn as line) and I have an ellipse which will move on…