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

Use one QPainter to paint multiple outputs at once: SVG and QImage

My Qt application uses a QPainter to draw a vector graphic. I need this graphic output twice, once as a vector output in SVG format, where I'm using QSvgGenerator, and once as a pixel format, where I'm using QImage. According to what I've found in…
Philipp
  • 957
  • 1
  • 6
  • 20
2
votes
2 answers

QPainter or QLabel is less costly to draw QPixmap

I have to create an Icon pixmap, two methods I am familiarized to do that, One is setting the pixmap as o QLabel and display it, and other is drawing pixmap using QPainter, ie Method one Icon::Icon { QLabel iconLab = new QLabel; QLabel…
Akhil V Suku
  • 870
  • 2
  • 13
  • 34
2
votes
1 answer

Declaring functions called when a mouse event ocurr in Qt

I'm a beginner in Qt when I run the following code I got these errors: no void MainWindow::mousePressEvent(QMouseEvent *f) member function declared in class 'mainwindow'. no void void MainWindow::paintEvent(QPaintEvent *e) member function…
sh ze
  • 169
  • 2
  • 5
  • 14
2
votes
1 answer

Draw on QTreeWidget With QPainter

I'm working on a little program and I have a bunch of panels in it. I want it so that when I focus into a panel, it draws a thin inline around it to show that it is focused. I got it working with all my panels except my tree view. Here's an example…
David Ludwig
  • 967
  • 2
  • 12
  • 26
2
votes
1 answer

How to prevent visible gaps/joins between polygons in QPainter with antialiasing

I'm drawing triangles/polygons in QPainter using antialiasing, which come from the rendering of 3D models. If two polygons are drawn immediately next to each other there is a gap between them. Here is some code (in PyQt) to demonstrate the…
xioxox
  • 2,526
  • 1
  • 22
  • 22
2
votes
1 answer

Use Clipping in Qt

Is it possible to use clipping in an widgets painEvent, if the widget is using stylesheets? The background and reason for my question is that I want to make the widget animating when it appears and disappears. (Something like a resizing circle or…
exilit
  • 1,156
  • 11
  • 23
2
votes
2 answers

Change origin point of QPainter

By default QPainter has its origin point in top-left corner. I want to draw shapes but all coordinates that I have are in cartesian system. So my question - how can I change the origin point to bottom-left corner? Sure, I can scale(1,-1) but then…
folibis
  • 12,048
  • 6
  • 54
  • 97
2
votes
1 answer

Optimizing QPainter drawing & Converting QVideoFrame straight to QPixMap

Some background info about my issue. My goal is to optimize drawing of images coming from webcam, the images come as QVideoFrame and are currently loaded in to QImage and drawn from there. This solution works fine, but drawing QImage is very slow on…
2
votes
0 answers

Qt optimize drawing on pixmap

I'm using Qpainter to draw on a QWidget. So, I have a QscrollArea about 1000 x 600 and a QPixmap inside. I would like to draw some segments (about 2000 lines) with QPainter on it. The QPixmap is very wide (about 150000)so I would like to do some…
Mike Shaw
  • 373
  • 7
  • 22
2
votes
2 answers

Qt : Smooth a circular mask. Remove Jagged edges

I am currently doing the following for putting a circular mask on my image. As a result only circular region of my image is displayed.This works fine however the image tends to have jagged edges (border). Any suggestion on how I could do this.
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
2
votes
1 answer

Get visible area of QPainter

I have an owner-drawn QWidget inside a QScrollArea, so when painting, and I want to paint only the parts that are visible. To do so, I need to have the rectangle of the visible area of the QPainter. The only candidates were QPainter::viewport(),…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
2
votes
0 answers

Qt for iOS QPainter::drawText hangs for a few seconds first time it is called

I'm using Qt for iOS 5.2 and when trying to draw text using QPainter, it will hang on that call for a few seconds (5 seconds on iPhone4 and around 3 on OSX). After that first time, it won't block anymore if I call it again. QImage image(QSize(200,…
EiN
  • 121
  • 1
  • 6
2
votes
1 answer

Avoid color quantization when painting translucent colors in Qt

I'd like to use Qt 5.2 to create images with alpha in them, but I'm finding that the color values are being quantized. Here's an example: QColor testColor(248, 64, 16, 2); QImage image(10, 10, QImage::Format_ARGB32); QPainter…
Frank Hunleth
  • 720
  • 4
  • 13
2
votes
1 answer

QPixmap copy contents of a square drawn into another image

I have an image onto which I draw a Rectangle as such. After that I am attempting to copy the contents of the rectangle onto another QLabel. This seems to work however i cannot seem to align the copied image starting from the left top corner of the…
MistyD
  • 16,373
  • 40
  • 138
  • 240
2
votes
1 answer

Python PyQt4 Qpainter active message

I was trying to display my QTabWidget text horizontally with the Tabposition set to 2 (left side). After searching around, i found the following code from this link. class FingerTabWidget(QtGui.QTabBar): def __init__(self, *args, **kwargs): …
Chris Aung
  • 9,152
  • 33
  • 82
  • 127