mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-20 17:32:15 -07:00
Don't use timers, Qt provides ShowEvent for anything necessary before the widget is shown.
This commit is contained in:
parent
1606676009
commit
9f493b2070
2 changed files with 17 additions and 8 deletions
|
|
@ -64,14 +64,6 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
|
||||||
|
|
||||||
// Connect slider for dynamic font size adjustment
|
// Connect slider for dynamic font size adjustment
|
||||||
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
|
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
|
||||||
|
|
||||||
// Resize after a little delay to ensure parent size is available
|
|
||||||
QTimer::singleShot(10, this, [this]() {
|
|
||||||
adjustFontSize(this->cardSizeSlider->value());
|
|
||||||
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
|
|
||||||
decrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
|
|
||||||
updateCardCount();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -92,6 +84,22 @@ void CardAmountWidget::paintEvent(QPaintEvent *event)
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardAmountWidget::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::showEvent(event);
|
||||||
|
|
||||||
|
adjustFontSize(this->cardSizeSlider->value());
|
||||||
|
updateCardCount();
|
||||||
|
|
||||||
|
if (parentWidget()) {
|
||||||
|
int width = parentWidget()->size().width();
|
||||||
|
int height = parentWidget()->size().height();
|
||||||
|
|
||||||
|
incrementButton->setFixedSize(width / 3, height / 9);
|
||||||
|
decrementButton->setFixedSize(width / 3, height / 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adjusts the font size of the card count label based on the slider value.
|
* @brief Adjusts the font size of the card count label based on the slider value.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
void hideElements();
|
void hideElements();
|
||||||
void showElements();
|
void showElements();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue