int strwidth = painter.fontMetrics().width(strTxt);//字符串显示的像素大小 painter.drawText(this->width()/2-strwidth/2,this->height(),m_strTxt);
或者painter.drawText(0,0,this->width(),this->height(),Qt::AlignCenter,strTxt);