custom widget update() and repaint() will not work
Unsolved
General and Desktop
-
So I have a widget for an image. I know that it does work in relation to the first call of the paint event but when I send in an image I can't get this to happen again
header:
#ifndef IMAGEDISPLAY_H #define IMAGEDISPLAY_H #include <QWidget> #include <QImage> class QPaintEvent; class ImageDisplay : public QWidget { Q_OBJECT public: explicit ImageDisplay(QWidget *parent = nullptr); virtual void paintEvent(QPaintEvent* event); void setImage(QImage img); signals: private: QImage toShow; }; #endif // IMAGEDISPLAY_H
source
#include "imagedisplay.h" #include <QtGui> ImageDisplay::ImageDisplay(QWidget *parent) : QWidget{parent} { //toShow = QImage(":/Images/Images/Columbine-Flower-Colors-768x768-tile.jpg"); } void ImageDisplay::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(QColor::fromRgb(255, 255, 255, 255)); QBrush solid = QBrush(QColor::fromRgb(255, 255, 255, 255), Qt::BrushStyle::SolidPattern); auto size = this->size(); auto offset = 4; painter.drawImage(QRect(0, 0, 768, 768), toShow); } void ImageDisplay::setImage(QImage img) { toShow = img; this->repaint(); }
-
"Will not work" is not a good description of what is happening versus what was expected.
Does it behave differently if you call QWidget::update() rather than QWidget::repaint()?void ImageDisplay::setImage(const QImage &img) { toShow = img; update(); }
Without code we cannot see if you are doing something that blocks the event loop or painting.
-
@AI_Messiah hi,
Might be a silly question but since you don't seem to be anything special with the image, why not use QLabel ?