I used the following codes:
QWdiget *widget=new QWidget(this);
QPainter painter(widget);
QRect rect=painter.window();
painter.eraseRect(rect);
QString text="Hello!";
painter.setBackgroundColor(QColor("white"));
painter.setPen(QColor("black"));
painter.drawText(rect,AlignHCenter,text);
but cannot see any word on the widget,I don't know why.