QLabel not refreshing with QPixmap "loadFromData"
I have this kind of code :
QLabel * label;
QPixmap * pixmap;
/* init */
/* loop */
The problem is that the label don't refresh. I suspect a problem of cache but i thought that there wasn't any implicit cache managment...
My current workaround is calling pixmap->fill() before reload the pixmap (or if i paint on the pixmap, the refresh is ok too).
I could also declare the QPixmap inside the loop, but i would like to avoid memory allocations as far as possible.
I would like to simply raise a kind of dirty flag to force the label redrawing.
What do you suggest please ?
You create a pixmap A. You set that pixmap A on the label which keeps a copy of it B. Then you change A. Why should the B change?
You use a pointer to the pixmap A instead of using it directly, but that does not matter at all to the Label: It gets a QPixmap and makes its copy. QPixmaps are implicitly shared, so making copies is pretty cheap.
Hmm... reading your post again I think I misunderstood it a bit in the first round.
Here is a test case :
class Test : public QLabel
void timerEvent(QTimerEvent *event);
QPixmap * m_Pixmap;
QBasicTimer * m_Timer;
@/* Test.cpp */
static const char data_black = "P1 1 1\n1";
static const char data_white = "P1 1 1\n0";
m_Pixmap(new QPixmap(1, 1)),
void Test::timerEvent(QTimerEvent event)
if(event->timerId() == m_Timer->timerId())
// update label
memcpy(m_data, (m_cpt++%2)?data_white:data_black, sizeof(m_data));
m_Pixmap->loadFromData((const uchar)(m_data), sizeof(m_data));
fprintf(stdout, "update data : \"%s\"\n", m_data); m_Timer->start(1000, this); }
@/* Main.cpp */
int main(int argv, char **args)
QApplication app(argv, args);
QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));