Well, there is the Qt basic drawing example, but unfortunately it is anything but basic. It shows a lot of confusing things that you don't need for drawing, but it does not show the simplest possible use case: drawing a line. Here, I give you a simple example:
Subclass QWidget:
{
Q_OBJECT
public:
~YourWidget();
protected:
};
class YourWidget: public QWidget
{
Q_OBJECT
public:
YourWidget(QWidget* parent=0);
~YourWidget();
protected:
void paintEvent(QPaintEvent*);
};
To copy to clipboard, switch view to plain text mode
Implement paintEvent:
{
painter.setPen(Qt::blue);
painter.drawLine(0, 0, width(), height()); // draws a diagonal line across your widget
painter.
setFont(QFont("Arial",
30));
painter.drawText(rect(), Qt::AlignCenter, "Your Widget"); // writes text onto your widget
}
void YourWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::blue);
painter.drawLine(0, 0, width(), height()); // draws a diagonal line across your widget
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Your Widget"); // writes text onto your widget
}
To copy to clipboard, switch view to plain text mode
This should draw a diagonal line across your widget and writes some text onto it. You can construct your whole time line widget from lines and text. I can't imagine what you could possibly do so wrong that it entirely breaks performance. Once you have lines and text under control, you can study the
QPainter documentation and proceed to more advanced drawing techniques. You can draw arcs and circles, rectangles, polygons, compound shapes, and use brushes and transparency for cool visuals. Happy studying.
Added after 39 minutes:
One more remark to your original question. When you learn how to draw lines, to do it fast means avoiding to draw unnecessary lines. For example, it does not make sense to draw three million lines on the millisecond resolution when you are showing a whole hour on your time line. Implement a zoom level based logic that decides when to draw down to the minute, second, or millisecond level. And as a more generic approach, you can determine if multiple vertical lines would be drawn on the same pixel. Say if you have 2000 pixels available in the horizontal direction, and you would want to draw three million lines onto them, then it is clear that many many lines would have to be drawn at the same horizontal coordinate. You can discard all but one of them and save yourself heaps of drawing time.
Bookmarks