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

QPainter - Draw Polygon with multiple holes

I am trying to draw a polygon with multiple holes in them with QPainter (QT5.8, win64). I am using the following code: QPainter pm(&image); QPen p(Qt::gray, 2); p.setCosmetic(true); pm.setPen(p); pm.setBrush(QBrush(color)); QPainterPath…
Richy
  • 534
  • 4
  • 13
2
votes
1 answer

PyQt5 Paint Circle Over Video in QLabel

I want to draw a circle that displays over a video at the cursor location when pressing the mouse. The video is playing in a QLabel object that is in a MainWindow. I’m using OpenCV to read frames from the webcam at 10 fps. I’m converting the…
slalomchip
  • 779
  • 2
  • 9
  • 25
2
votes
2 answers

How to draw with QPainter on top of already placed QLabel or QPixmap?

While experimenting with Python and PyQt5 I got stuck on a problem. I have in my GUI few labels (QLabel) and images (QPixmap) and I want to draw something on them, depending on what the main program does. I can't figure out how though. For example,…
cyanidem
  • 103
  • 2
  • 9
2
votes
3 answers

Using QtConcurrent to load a Pixmap and paint it

I'm trying to create a Tile rendering program. Heres some basic code. Header class Tile: public QGraphicsItem { public: Tile(void); ~Tile(void); QGraphicsPixmapItem *tileItem; void update(QPainter *painter, const QStyleOptionGraphicsItem…
sleeping.ninja
  • 607
  • 1
  • 10
  • 21
2
votes
1 answer

Integrating QPainter in PyQt GUI

I'm trying to use QPainter-made object along with native widgets of PyQt in one layout and having a difficulty doing so. I've tried using addWidget() to add it to the layout but no luck. class window(QWidget): def __init__(self): …
AmmarYasir
  • 92
  • 9
2
votes
1 answer

Undesirable black border on my rect when i draw it with QPainter.drawRect()

I have an undesirable black line of one or two pixels on the top of my rect when i use drawRect(). So my rect doesn't fill my widget completely. My code : QPainter Painter(this); QString TmpColor; int R, G, B, A; TmpColor = c_LabColor; R =…
2
votes
1 answer

How to use QPropertyAnimation with QPainter to draw an arc

I'm writing a desktop widget that performs the function of a system monitor. Using a QPainter I draw an arc which represents a graphical representation of a cpu usage level. Every second a paintevent redraw this arc with a span angle based on a…
Artem
  • 563
  • 3
  • 17
2
votes
1 answer

QPainter point size is 1 pixel and can not be changed

I am trying to draw points with a costumed size, but changing the pen does nothing. Every point I draw is one pixel size. Here is my code: class Diedrico(QWidget): def __init__(self, parent): super().__init__(parent) def…
Jaime02
  • 299
  • 7
  • 21
2
votes
1 answer

expand the size of QPaintDevice after it is initialzed

A little Context I'm trying to make a QSplashScreen with a custom animation. I've tried many different approaches, with each failures. Mostly, my main technique was to create a new Class which inherits from QSplashScreen and then plan with the…
PyThagoras
  • 195
  • 2
  • 18
2
votes
1 answer

Custom QStyledItemDelegate to draw text with multiple colors

I want to display two columns inside a QTableWidget showing the differences between two stings (calculated by some Levenshtein Distance algorithms before). The parts are stored inside the data of each QTableWidgetItem, as a QStringList. The first…
Tobias Leupold
  • 1,512
  • 1
  • 16
  • 41
2
votes
1 answer

My QPainter neither draws the lines nor throws an error, how can I fix this?

Basically I'm trying to draw a border around my frameless window. It's size is 550 and 407. I create my QPainter then my lines and in the end I'm trying to draw them. def draw_border(self): painter = QPainter() painter.begin(self) pen =…
leon52
  • 99
  • 11
2
votes
1 answer

QPen setCosmetic does not work in high QGraphicsView scale

I have a QGraphicsView and a QGraphicsItem that added to graphicsView's scene. I override QGraphicsView wheelEvent to do scale view, but i want my graphics item width does not change. For this purpose i set cosmetic true for pen in graphics item…
Mohsen
  • 308
  • 1
  • 11
2
votes
1 answer

QPainterPath drawing and placering items along multiple paths

I have from previous codelines developed and added some special behaviour. The idea is to draw small circle shapes on a certain path inside rectangular shape and circular shape and place them according to the distance given in advance. I want to…
Pavel.D
  • 561
  • 1
  • 15
  • 41
2
votes
1 answer

Correct way to paint progressively with pyqt5

I've a widget that is basically a circle. I want to draw it progressively so I need to draw it in steps (imo). With the following code, I have achieved what I want. However, there's a problem. I'm passing a new event to the paintEvent function,…
Btc Sources
  • 1,912
  • 2
  • 30
  • 58
2
votes
2 answers

Why is the widget with a custom painting not visible?

So I'm trying to build a simple PyQt application with a custom widget. However, the painter does not paint anything. If I comment out line 44-45 (label = QLabel('Map');box.addWidget(label)), I can see a big colored rectangle. However, when I try to…
Mia
  • 2,466
  • 22
  • 38