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

Using QPainter and paintEvent to draw circles on a Pixmap that is contained in a QLabel in PYQT5

I'm pretty new to PYQT5 and I wanted to draw a circle on a Pixmap that is contained in a QLabel in the MainWindow UI on PYQT5 with this code: from PyQt5 import QtCore, QtGui, QtWidgets background_image_path = '001_01_01_041_05.png' class…
user_13439903
  • 91
  • 1
  • 8
3
votes
1 answer

How to draw smoothly using QPainter, QOpenGLPaintDevice and QOpenGLWidget on retina display?

The drawing is very laggy when I try to draw using QWidget and QPainter. I decided to accelerate the drawing by using QOpenGLPaintDevice and QOpenGLWidget. But the rounded corners of shapes are very rude, comparing to drawing on regular…
Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61
3
votes
1 answer

QPainter drawing lines - configuring line softness (horizontal opacity gradient)

I am looking for a way to apply a horizontal opacity gradient when painting QLine elements using QPainter. Put simply, I want to be able to have the line opacity decrease the further away from the line center it is being painted. The effect I want…
Basti Vagabond
  • 1,458
  • 1
  • 18
  • 26
3
votes
2 answers

How to draw darkened QPixmap?

I'm looking for a fast and effective way to draw a QPixmap with QPainter, but have the pixmap appear darker then normal. Is there some sort of filter or effect that can be applied to either the QPixmap or QPainter while drawing to create this…
Griffort
  • 1,174
  • 1
  • 10
  • 26
3
votes
2 answers

How to create custom 3D looking button in Qt?

I'm trying to create the following custom button: To do this I've create the class and overrided paintEvent: void Widget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QPen…
elgolondrino
  • 665
  • 9
  • 33
3
votes
1 answer

paint over QLabel with PyQt

For a Python project, I have to draw an image with a painter over a Qlabel widget already filled by a picture. My problem is that my image is systematically drawn behind my Label. I simplified the problem by this code, my goal is to paint…
T.C
  • 31
  • 1
  • 2
3
votes
0 answers

White Pixel artifacts when using drawImage in QPainter Pyside

I'm painting an image in a QPainter object with: QPainterObject.drawImage(QtCore.QPoint(0, 0), image) The image itself is huge, (12.000 x 25.000 pixels). When I scale the picture near it's "original" scale everything is fine, but when I reduce its…
3
votes
1 answer

How to efficiently draw images using QPainter?

I want to draw a custom made Pixmap on QLabel. I have to show the image in a circle and the widget has animation on mouse hover (eg, outline color highlight, and property animation too). I tried drawing the entire image inside paintEvent of the…
vaishak
  • 63
  • 7
3
votes
1 answer

Qt, QTransform rotation

I'm trying to draw text "on cylinder". It means, that I have five rows of text. Top row is rotated by the X axis for 10 degrees. The second for 5 degrees. The middle is not rotated at all. The four's row is rotated for -5 degrees. The five's is…
3
votes
1 answer

QT 5.7 QPainter line aligment

I am working with QT 5.7 and C++. At the moment I try to get used to draw my own widgets with the QPainter class. But I noticed a problem I couldn't solve. I try to draw a border line extactly at the widget border but if I do so: void…
Michael
  • 595
  • 5
  • 19
3
votes
2 answers

Text is not antialiased while using QPainter::drawText()?

While i'm trying to draw text using QPainter::drawText() the text is not antialiased (comparing to MS word) void TextLabel::paintEvent(QPaintEvent*) { QPainter p(this); p.setRenderHint(QPainter::TextAntialiasing); QFont font; …
IMAN4K
  • 1,265
  • 3
  • 24
  • 42
3
votes
1 answer

Unable to paint on Qt Widget, shows error "paintEngine: Should no longer be called"

I have created a widget using Qt Creator such a way that it has two sub windows inside a main window and some push buttons to load, save images, set pen width and color to paint on the window. But when i start to paint it gives me error saying …
beginMyCoding
  • 31
  • 1
  • 3
3
votes
3 answers

draw in a QFrame on clicking a button.

Say there is a QPushButton named "Draw", a QLineEdit and a QFrame. On clicking the button I want to take a number from QLineEdit and draw a circle in a QFrame. How can I do this? Please provide me with the code. P.S. The problem is that draw methods…
Narek
  • 38,779
  • 79
  • 233
  • 389
3
votes
1 answer

Drawing line render issue in a QTableWidgetItem

I would like to draw a line inside QTableWidgetItem. To draw the line I have reimplemented the QStyledItemDelegate::paint method. But, when I'm scrolling or selecting an item in the QTableWidget. Some of the items loose their drawing effect. Here's…
Simon
  • 1,522
  • 2
  • 12
  • 24
3
votes
1 answer

QPainter with Qt::AlignCenter does not center text correctly

I want to do a fairly simple drawing where I write a two pieces of text above each other in the center of the circle. My code: painter->drawText(QRectF(0, 0, m_iSize, m_iSize), Qt::AlignCenter, m_sAlias + "\n" + m_sCode); where m_iSize is the…
Resurrection
  • 3,916
  • 2
  • 34
  • 56