demo: center window on first show

Looks better than before.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-05-05 20:23:35 +08:00
parent 1c6e02d81b
commit e7f434c5a4
7 changed files with 40 additions and 3 deletions

View File

@ -41,6 +41,16 @@ MainWindow::MainWindow(QWidget *parent, const Qt::WindowFlags flags) : Frameless
MainWindow::~MainWindow() = default;
void MainWindow::showEvent(QShowEvent *event)
{
FramelessMainWindow::showEvent(event);
static bool exposed = false;
if (!exposed) {
exposed = true;
FramelessWidgetsHelper::get(this)->moveWindowToDesktopCenter();
}
}
void MainWindow::initialize()
{
m_titleBar.reset(new StandardTitleBar(this));

View File

@ -44,6 +44,9 @@ public:
explicit MainWindow(QWidget *parent = nullptr, const Qt::WindowFlags flags = {});
~MainWindow() override;
protected:
void showEvent(QShowEvent *event) override;
private:
void initialize();

View File

@ -40,6 +40,16 @@ MainWindow::MainWindow(QWidget *parent) : FramelessWidget(parent)
MainWindow::~MainWindow() = default;
void MainWindow::showEvent(QShowEvent *event)
{
FramelessWidget::showEvent(event);
static bool exposed = false;
if (!exposed) {
exposed = true;
FramelessWidgetsHelper::get(this)->moveWindowToDesktopCenter();
}
}
void MainWindow::initialize()
{
resize(800, 600);

View File

@ -41,6 +41,9 @@ public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
void showEvent(QShowEvent *event) override;
private:
void initialize();

View File

@ -48,10 +48,19 @@ Widget::~Widget() = default;
void Widget::timerEvent(QTimerEvent *event)
{
FramelessWidget::timerEvent(event);
if (!m_clockLabel) {
return;
if (m_clockLabel) {
m_clockLabel->setText(QTime::currentTime().toString(FRAMELESSHELPER_STRING_LITERAL("hh:mm:ss")));
}
}
void Widget::showEvent(QShowEvent *event)
{
FramelessWidget::showEvent(event);
static bool exposed = false;
if (!exposed) {
exposed = true;
FramelessWidgetsHelper::get(this)->moveWindowToDesktopCenter();
}
m_clockLabel->setText(QTime::currentTime().toString(FRAMELESSHELPER_STRING_LITERAL("hh:mm:ss")));
}
void Widget::initialize()

View File

@ -45,6 +45,7 @@ public:
protected:
void timerEvent(QTimerEvent *event) override;
void showEvent(QShowEvent *event) override;
private:
void initialize();

View File

@ -728,6 +728,7 @@ void FramelessQuickHelper::itemChange(const ItemChange change, const ItemChangeD
}
Q_D(FramelessQuickHelper);
d->attachToWindow();
d->moveWindowToDesktopCenter(); // Temp hack
}
}