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
4
votes
1 answer

How do I draw a QFont anti-aliased when the OS has anti-alias turned off?

When I use a QPainter to drawText onto a QPixmap using a QFont, it appears anti-aliased when the OS has anti-alias enabled, but not when it doesn't even though I am explicitly setting render hints of the painter and strategy of the font: QPainter…
jtooker
  • 1,043
  • 1
  • 8
  • 22
4
votes
1 answer

How to use QPainter for overlaying in QOpenGLWidget

I've received the problem, using QPainter for overlaying in QOpenGLWidget Qt. I create a CameraSurface_GL class that draw yuv image received from ip camera. Here's my code: #include "camerasurface_gl.h" #include #include #include…
4
votes
1 answer

QSS properties for custom widget: How to implement hover and pressed states

I found this example on the web on how to implement custom properties accessible from QSS for custom QWidgets: https://wiki.qt.io/Qt_Style_Sheets_and_Custom_Painting_Example Does anyone know how can I implement the widget so that I can have…
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
4
votes
2 answers

How to write a values around a circle using QPainter class without rotating?

The question is simple ! I want something like this using QPainter class. i dont want values to be rotated. but using QPainter::rotate method I am getting the values like this(rotated format). Can someone help me to draw the circle with values…
Arun
  • 2,247
  • 3
  • 28
  • 51
4
votes
3 answers

Rich text to image in QT

In my application , have a QTextEdit dialog that accepts Rich Text Input. I need to convert this input in to an image for some purpose . If it was Plain text i could use DrawText associated with the QPainter class . But Rich text cannot be dealt the…
J V
  • 515
  • 1
  • 5
  • 15
4
votes
4 answers

Using QPainter when every time I receive some data

I am a beginner in Qt, and I want to use QPainter. My process is like this: I receive data coordinates (x,y) from the serial port, like (1,1), (2,3), etc. I want to draw these points in a window every time I receive data. I see the QPainter is…
DarkPirate
  • 55
  • 1
  • 7
4
votes
2 answers

What is wrong with this attempt to render rotated ellipses in Qt?

1. Goal My colleague and I have been trying to render rotated ellipsoids in Qt. The typical solution approach, as we understand it, consists of shifting the center of the ellipsoids to the origin of the coordinate system, doing the rotation there,…
user2514673
  • 109
  • 1
  • 7
4
votes
1 answer

Qt draw over vertical layout

I have QVBoxLayout with multiple children and I want to be able to draw on top of it. I've tried implementing paintEvent(QPaintEvent *) for the layout but everything I draw stays under the children. How can I do it? I'd be thankful for sample code.
Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107
4
votes
1 answer

Creating one QPainter object and using it in paintEvent

The common use of QPainter is inside a widget's paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing. This is from QPainter Class Reference. What if…
Ashot
  • 10,807
  • 14
  • 66
  • 117
4
votes
1 answer

win32 controls (QWinHost) not painted on layered (ie. semi-transparent) widget (WS_EX_LAYERED)

I ported a win32 control using QWinHost, and put it on a layered (semi-transparent) widget. When I set WS_EX_LAYERED flag, then paint not occurred for win32 ported control. SetWindowLong(winId(), GWL_EXSTYLE, …
hassan deldar
  • 293
  • 1
  • 11
3
votes
0 answers

How to use Flutter Canvas for PDF export and printing

Question Is there a way in Flutter to generate a PDF directly from a Flutter Canvas? Without writing separate drawing/rendering code for PDF export? Details We are currently implementing an application in Flutter which provides an editable canvas to…
Fabian
  • 1,824
  • 3
  • 19
  • 35
3
votes
1 answer

QPainter Cache Possible?

I've Pie Shaped widgets that needs extensive paintings. So I want to cache the QPainter Once it have been painted in paintEvent. and reuse it latter. Is there any direct or hacky way of doing this ?
Neel Basu
  • 12,638
  • 12
  • 82
  • 146
3
votes
1 answer

QPixmap / QPainter showing black window background

I am following an example from the PyQt5 book by Martin Fitzpatrick. When I run the following code, the background is black and the line is not drawn: import sys from PyQt5 import QtCore, QtGui, QtWidgets, uic from PyQt5.QtCore import Qt class…
Joe
  • 80
  • 2
  • 10
3
votes
1 answer

Insert Image into QGridLayout and Draw on top of image in PyQt5

I'm pretty new to PyQt and am trying to make an application with a QPixmap on the left, which can be drawn on, and a QTextEdit on the right (for a simple OCR GUI). I looked at: PyQt5 Image and QGridlayout but I couldn't connect it with the code…
John
  • 178
  • 10
3
votes
3 answers

Dragging object around a QWidget in Qt

I am trying to make a custom widget in Qt Creator that supports dragging objects around. At its simplest form, the widget has a QRect (or any other shape), on which I can click and then drag it around the widget. Once I release the mouse button, the…
John
  • 31
  • 4