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

Qt 4.7 - Drawing a 2 point line with dynamic feedback using paintEvent

so I am trying to draw a line between two points. Left mouse click starts the line then I would like the line to by dynamically drawn as the mouse moves (almost like a preview of the line). Left mouse click again and the line will be permanently…
Josh O'Hara
  • 33
  • 1
  • 3
-2
votes
1 answer

Simple form with pixel manipulation in Qt

I'm completely newbie to Qt i want to create a 800X600 window that just show some circle and be able to manipulate pixels of the form. there is no interaction between user and form(no click, no dblclick,...) it just shows some circles with one color…
Mason
  • 165
  • 1
  • 1
  • 10
-2
votes
1 answer

Prevent QPainter point from going outside the window scope

I have a PyQt application in which I have to implement a drap n drop functionality of points made via QPainter. My problem is that I'm even able to drag those points outside the window scope e.g. I can drag the point to the title bar or taskbar and…
Voldemort
  • 175
  • 5
  • 20
-8
votes
1 answer

Construct QPushButton with QIcon alignleft and text center align

I would like to create QPushButton with QIcon left align (not to the center as default) and text center align. I don't want to use a style sheet. I know that might be possibly using QPainter but I wasn't able to do it. I had little clue and tried…
mumulala
  • 1
  • 5
-8
votes
4 answers

Invalid use of 'this' in non-member

I have a problem - discussed a lot previously, but all solutions I saw doesn't work here. What is wrong in this code? main.cpp:8:19: error: invalid use of ‘this’ in non-member function #include #include #include…
user2692713
  • 1
  • 1
  • 2
1 2 3
44
45