void ViewWidget::paintEvent(QPaintEvent* ev){ qDebug()<<"repaint"; QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget,&opt,&p,this); if (data.size()>0){ QFontMetrics metrics(font()); QColor color; int x =metrics.width(data.at(0)); int y =metrics.height(); int sm =0; int n_str=1; p.setPen(QColor(Qt::black));for (int i = 0; i < data.size(); ++i) { if ( data.at(i)==10) {n_str++;x=0;} else { p.drawText(x, y*n_str, QString( data.at(i))); sm=metrics.width(data.at(i));if (sm==0) sm =metrics.width(" "); x += sm;} } } }