开发者

QT drawing without erasing widget

I have a QWidget-derived class. In the constructor I say:

setPalette(QPalette(QColor(250,250,200)));
setAutoFillBackground(true);

Then in my widget's paintEvent() I say:

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

There is also an up开发者_开发知识库dateNow() slot...which just calls update(). How can I make sure my palette doesn't get erased after that update call?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜