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
6
votes
2 answers

how to merge two images into one using QImage and QPainter in qt?

Hi I am developing a blackberry10 app. Inside the app I have two images and I just need to merge these two images into a single image. There is no function in Cascades to combine them. When I posted this in the blackberry developer forum I was…
user2100249
  • 61
  • 1
  • 1
  • 2
6
votes
1 answer

How to create a text along with curve using QPainterPath

I am trying to build a arc with some text. I am able to create the arc and I can place the text along with curve. But so far I cant find a way rotate text perpendicular to the curve. Here is the code I am trying from __future__ import…
Achayan
  • 5,720
  • 2
  • 39
  • 61
5
votes
1 answer

Intersection point of QPainterPath and line (find QPainterPath y by x)

I have QPainterPath. I need to find y coordinate of QPainterPath by x. I found intersected() method in QPainterPath. So, I created new QPainterPath, which is line from left to right edge of my path's bounding rect with x coordinate, to find point as…
Funt
  • 399
  • 8
  • 23
5
votes
1 answer

How to draw a QPixmap with transparency

I've got a QPixmap and I would like to draw it on a QWidget. However, I would like to make it 50% transparent so that the background can be seen below. How can I do that?
laurent
  • 88,262
  • 77
  • 290
  • 428
5
votes
1 answer

PyQt print QWidget

Am trying to follow the documentation for printing a QWidet and am getting an error. When I run the following code I get QPaintDevice: Cannot destroy paint device that is being painted. import sys from PyQt4 import QtGui, QtCore class…
Spencer
  • 1,931
  • 1
  • 21
  • 44
5
votes
1 answer

Sharing OpenGL VAO/VBO/etc. via QGLWidget

I am using a 3 layer hierarchy of QGLWidgets to share shaders and vertex data between 5 OpenGL viewports in my CAD-like app. The root context is used for compiling application-wide shaders, the per document context is used to share model vertex…
cmannett85
  • 21,725
  • 8
  • 76
  • 119
5
votes
2 answers

"QPainter::drawRects: Painter not active " error C++/QT

I'm a beginner at Qt and c++ and I wanted to see how to use a QPainter and events in Qt but I got stuck because of an error message during the execution, my original code: the main.cpp #include "customwidget.h" #include int main(int…
N.D.
  • 157
  • 1
  • 2
  • 10
5
votes
1 answer

paintEvent in QTableView derived class: Paint device returned engine == 0, type: 1

As a follow up of Qt load indicator by animated image (aka preloader) or alternative? I try to paint inside a QTableView. But when I initialize the QPainter I get the following warnings. QWidget::paintEngine: Should no longer be…
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
5
votes
1 answer

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored

This question is further development of this post and is different, though may seem similar as this one. I am trying to reimplement QHeaderView::paintSection, so that the background returned from the model would be honored. I tried to do this void…
Serge
  • 1,027
  • 14
  • 21
5
votes
3 answers

QPainter DrawImage CenterAligned

Is there any way to draw an image on QPainter center aligned? I see QPainter::drawText gives us this provision but drawImage does not. I have one source rect, target rect and an image. when the source size is small the image gets drawn on the left…
user2147688
  • 95
  • 1
  • 9
5
votes
3 answers

Qt painting without clearing the background

I'm using a QPainter to get some graphics on a window. Unfortunately every time the paintEvent() function is called, the whole window is cleared. How can I draw without clearing? I.e. how do I leave the stuff from previous paint event untouched? I'm…
viraptor
  • 33,322
  • 10
  • 107
  • 191
5
votes
2 answers

What's the point in QPainter::drawConvexPolgon

From the docs: QPainter offers two methods of painting QPolygons: drawPolygon and drawConvexPolygon. Nowhere in the documentation is it made clear what the difference between them is. Additionally, the drawConvexPolygon docs state If the supplied…
Nils Werner
  • 34,832
  • 7
  • 76
  • 98
5
votes
2 answers

Stroking a path only inside/outside?

Given a QPainterPath how can I stroke the path only on the inside or outside edge of the path (or left- or right-side for non-closed paths)? QPainter::strokePath() centers the pen along the path and causes the same amount of ink to fall on both…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
5
votes
2 answers

QtQuick 2.0 vs QGraphicsView (QPainter)

I'm writing right now an application in Python (PyQt / PySide), which should visualise and should give the possibility to edit complex dataflow graphs (like nodes in blender). Additional I want these nodes to display opengl 3D objects (small opengl…
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
5
votes
1 answer

How to disable multiple auto-redrawing at resizing widgets in PyQt?

I have a PyQt4 program with widgets whose content redraws very slowly (it's ok, because of my tasks). And when I trying to resize those widgets, program is trying to redraw a lot of times while mouse is not released. That's a lot of freezes. I want…
Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50