There is a window with caste diagrams in which you can change the grid spacing in time and scale in pixels:
After each change, the diagram is redrawn. The time scale and the chart itself are 2 different widgets placed on two different scrolls.
The task: to draw the signature of the vertical lines is centered, and so that no one climbs on anyone.
Here, on SO, I looked at the decision that you can find out how much the pixels will occupy the text. So you can take the size of the maximum signature and dance from him already:
lastNumber = static_cast<unsigned int>(dialog->commonSAGridSpacing * width() / dialog->commonSAScale); QFont currentFont = _painter->font(); QFontMetrics fm(currentFont); unsigned int size = static_cast<unsigned int>(fm.width(QString::number(lastNumber))); The scale itself is redrawn with captions:
unsigned int maxNumberSizePix = numbersSizePix(painter); unsigned int separatorPX = 4; unsigned int shift = (maxNumberSizePix + separatorPX) / dialog->commonSAScale + 1; for (unsigned int counter = dialog->commonSAScale; counter < static_cast<unsigned int>(width()); counter += dialog->commonSAScale * shift) { QRectF currentRect(counter - maxNumberSizePix / 2, 2, maxNumberSizePix, height() - 4); painter->drawText(currentRect, Qt::AlignCenter, QString::number(static_cast<int>(counter / dialog->commonSAScale * dialog->commonSAGridSpacing))); } Problem: for some reason, there are situations when the numbers (for example, 5229 at the top of the diagram) do not fit into your QRect and a small trimming of the displayed one occurs.
drawText'the entire rectangle with delimiters - IMHO the creeping numbers, of course, is also unpleasant. but better than cropped ... - Fat-Zer