Fix the size of the time elapsed and time remaining labels on the track slider, so they don't move the slider around while it's being dragged.
This commit is contained in:
parent
7d0bc4830f
commit
ee5facbd01
@ -10,10 +10,25 @@ TrackSlider::TrackSlider(QWidget* parent)
|
||||
ui_.elapsed->setFont(font);
|
||||
ui_.remaining->setFont(font);
|
||||
|
||||
UpdateLabelWidth();
|
||||
|
||||
connect(ui_.slider, SIGNAL(sliderMoved(int)), SIGNAL(ValueChanged(int)));
|
||||
connect(ui_.slider, SIGNAL(valueChanged(int)), SLOT(ValueMaybeChanged(int)));
|
||||
}
|
||||
|
||||
void TrackSlider::UpdateLabelWidth() {
|
||||
// We set the label's minimum size so it won't resize itself when the user
|
||||
// is dragging the slider.
|
||||
QString old_text = ui_.elapsed->text();
|
||||
ui_.elapsed->setText("0:00:00");
|
||||
ui_.elapsed->setMinimumWidth(0);
|
||||
int width = ui_.elapsed->sizeHint().width();
|
||||
ui_.elapsed->setText(old_text);
|
||||
|
||||
ui_.elapsed->setMinimumWidth(width);
|
||||
ui_.remaining->setMinimumWidth(width);
|
||||
}
|
||||
|
||||
QSize TrackSlider::sizeHint() const {
|
||||
int width = 500;
|
||||
width += ui_.elapsed->sizeHint().width();
|
||||
@ -75,3 +90,13 @@ void TrackSlider::ValueMaybeChanged(int value) {
|
||||
UpdateTimes(value);
|
||||
emit ValueChanged(value);
|
||||
}
|
||||
|
||||
bool TrackSlider::event(QEvent* e) {
|
||||
switch (e->type()) {
|
||||
case QEvent::ApplicationFontChange:
|
||||
case QEvent::StyleChange:
|
||||
UpdateLabelWidth();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ class TrackSlider : public QWidget {
|
||||
// QWidget
|
||||
QSize sizeHint() const;
|
||||
|
||||
// QObject
|
||||
bool event(QEvent *);
|
||||
|
||||
static QString PrettyTime(int seconds);
|
||||
|
||||
public slots:
|
||||
@ -29,6 +32,7 @@ class TrackSlider : public QWidget {
|
||||
|
||||
private:
|
||||
void UpdateTimes(int elapsed);
|
||||
void UpdateLabelWidth();
|
||||
|
||||
private:
|
||||
Ui::TrackSlider ui_;
|
||||
|
@ -25,6 +25,9 @@
|
||||
<property name="text">
|
||||
<string>0:00:00</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user