views:

264

answers:

1

Hello,

If I have a derived object of QWidget class and on slot function in it I have an update(). here is some pseudocode:

*.h
   slot:
     updateNow();

*.cpp
constructor()
{
  setPalllete(QPallete(QColor(250,250,200)));
  setAUtoFillBackground(true);
}
updateNow()
{
  update();
}

paintEvent()
{
  QPainter painter(this);
  painter.drawRect(1,2,3,4);
}

So how should I don't get erased my pallete after update() call?

P.S. - Sorry for my English and only pseudocode.

+1  A: 

I don't have any problems with the following:

#include <QApplication>
#include <QWidget>
#include <QPalette>
#include <QPaintEvent>
#include <QPainter>

class Test : public QWidget
{
public:
  Test()
  {
    setPalette(QPalette(QColor(250, 250, 200)));
    setAutoFillBackground(true);
  }

protected:
  virtual void paintEvent(QPaintEvent*)
  {
    QPainter painter(this);
    painter.drawRect(10, 20, 30, 40);
  }

  virtual void mousePressEvent(QMouseEvent*)
  {
    update();
  }
};

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);

  Test myTest;
  myTest.show();

  return app.exec();
}

The rectangle draws, and stays after I click, which triggers update. What are you seeing?

Bill
I see it too! But i don't need erasing widget after update(); function. I need to draw new rectangle on top of my widget :)
faya
I am sorry. I do not understand what is wrong.
Bill