c++ - Qt - Can't paint over axis values -
i'm coding plot window real-time input in qtcreator, data waveforms writes on in cyclic manner user-specified period.
the actual plotter , axis initialization working great, i'm having trouble getting time axis update @ end of each period. thought erasing data in label area , re-drawing using new values work, instead entire axis erased @ end of first period. suspect problem use of qpainter.
first post, go easy on me.
void t_axiswidget::initaxis(double window_period) { period = window_period; t_pixmap = qpixmap(size()); t_pixmap.fill(qt::black);
qpainter painter(&t_pixmap); painter.initfrom(this); painter.setpen(qt::red); painter.drawline(0, 0, size().width(), 0); painter.drawline(0, 0, 0, tick_length); //always draw first tick @ origin int tick_interval = size().width()/(num_ticks); int remainder = (size().width()%(num_ticks))-1; //pixels skipped cover entire axis painter.drawtext(0, tick_length+2, tick_interval/2, size().height()-tick_length+2, qt::alignleft | qt::aligntop, qstring::number(0)); qdebug() << "width = " << size().width(); qdebug() << "interval = " << size().width()/(num_ticks); for(int i=tick_interval; i<=size().width()-tick_interval; i+=tick_interval) { if (remainder>0) { ++i; //space ticks pixel apart achieve spread --remainder; qdebug() << "remainder = " << remainder; qdebug() << "tick = " << i; } painter.drawline(i, 0, i, tick_length); painter.drawtext(i-(tick_interval/2), tick_length+2, tick_interval, size().height()-tick_length+2, qt::alignhcenter | qt::aligntop, qstring::number((period/(double)num_ticks)*(i/tick_interval))); } painter.drawline(size().width()-1, 0, size().width()-1, tick_length); painter.drawtext(size().width()-tick_interval/2, tick_length+2, tick_interval/2, size().height()-tick_length+2, qt::alignright | qt::aligntop, qstring::number(period)); }
void t_axiswidget::settvalues (int multiplier) { double start = period*multiplier; int tick_interval = period/num_ticks;
qpainter painter(&t_pixmap); painter.initfrom(this); painter.setpen(qt::red); qrect eraseblock(0, tick_length+2, size().width(), size().height()); painter.eraserect(eraseblock); painter.drawtext(0, tick_length+2, tick_interval/2, size().height()-tick_length+2, qt::alignleft | qt::aligntop, qstring::number(start)); for(int i=1; i<num_ticks; i++) { painter.drawtext(i*tick_interval-(tick_interval/2), tick_length+2, tick_interval, size().height()-tick_length+2, qt::alignhcenter | qt::aligntop, qstring::number(start+(i*period/(double)num_ticks))); } painter.drawtext(size().width()-(tick_interval/2), tick_length+2, tick_interval/2, size().height()-tick_length+2, qt::alignright | qt::aligntop, qstring::number(period*multiplier));
}
void t_axiswidget::paintevent(qpaintevent * /* event */) { qstylepainter painter(this); painter.drawpixmap(0, 0, t_pixmap); }
Comments
Post a Comment