forked from github_mirror/framelesshelper
demo: center window on first show
Looks better than before. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
1c6e02d81b
commit
e7f434c5a4
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -41,6 +41,9 @@ public:
|
|||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
|
|
@ -728,6 +728,7 @@ void FramelessQuickHelper::itemChange(const ItemChange change, const ItemChangeD
|
|||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->attachToWindow();
|
||||
d->moveWindowToDesktopCenter(); // Temp hack
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue