Answer the question
In order to leave comments, you need to log in
How to draw on QPixmap?
Hello everyone. There is a class that inherits from QLabel. It is necessary to install a picture from 2 QPixmap into it. I decided to create a third QPixmap and redraw the image in paintEvent
void MainWindow::paintEvent(QPaintEvent*)
{
QPixmap *pixmap=new QPixmap(this->size().width(), this->size().height());
QPainter *painter=new QPainter(pixmap);
painter->drawPixmap(0, 0, this->size().width(), this->size().height(), QPixmap(":/rectB.png"));
painter->drawPixmap(0, 0, this->size().width(), this->size().height(), QPixmap(":/CheckFF.png"));
painter->end();
delete painter;
pix= *pixmap; //pix- private поле класса
setPixmap(pix);
delete pixmap;
}
Answer the question
In order to leave comments, you need to log in
your mistakes.
1. QPixmap is itself a shared ownership pointer; if you need to create it for a short time - do it on the stack, no new!
1.1. So is QPainter, only it's a sole proprietorship pointer. By the way, this once played a cruel joke with one of my programs when it ate all the memory.
2. Why do we need Pixmap generation in the form redrawing procedure? If your descendant draws a picture correctly on its own, generate it on the “something has changed” event.
Further, if there can be a finite but sufficiently large number of pictures (for example, thousands), you can set up a cache where the last twenty are stored prepared, for example. If there are few pictures (up to a hundred), it is better to prepare them all when loading the program.
Lord, what are you doing?
What is this anyway? What for?
So do you want to label the QPixmap once or redraw it yourself each time? If redrawing, then why create QPixmap on the heap and also reassign it to the field?
Resizing something to do with it? Are you trying to solve the problem at any cost?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question