- typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
- Qt::AlignLeft | Qt::AlignTop,
- format_time(offset_, tick_prefix_)).width() +
+ // Precision is the number of fractional digits required, not
+ // taking the prefix into account (and it must never be negative)
+ tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0);
+
+ tick_period_width = (tick_period / scale_).convert_to<double>();
+
+ const QString label_text = Ruler::format_time_with_distance(
+ tick_period, max_time, tick_prefix, time_unit_, tick_precision);
+
+ label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
+ Qt::AlignLeft | Qt::AlignTop, label_text).width() +