Skip to content

Commit

Permalink
fix: The dialog size abnormally on multi-screen
Browse files Browse the repository at this point in the history
and the screens have different device pixel ratios

fix: linuxdeepin/internal-discussion#1186
  • Loading branch information
zccrs committed Apr 17, 2019
1 parent 4db6391 commit 320d896
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/widgets/dabstractdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,30 @@ void DAbstractDialog::resizeEvent(QResizeEvent *event)

D_DC(DAbstractDialog);

if (!d->mouseMoved) {
setDisplayPosition(displayPosition());
}

if (d->bgBlurWidget)
d->bgBlurWidget->resize(event->size());

Q_EMIT sizeChanged(event->size());
}

void DAbstractDialog::showEvent(QShowEvent *event)
{
D_DC(DAbstractDialog);

// 不要在resizeEvent中改变窗口geometry,可能会导致以下问题。在双屏开启不同缩放比时:
// 屏幕A缩放为1,屏幕B缩放为2。窗口初始在屏幕B上,此时大小为 100x100,则其缩放
// 后的真实大小为200x200,由于窗口管理器会对未设置过位置的窗口自动布局,接下来
// 窗口可能会因为位置改变而被移动到屏幕A上,则此对话框的大小将变化为 200x200,
// 触发了resize事件,紧接着又会尝试将窗口位置更新到鼠标所在屏幕的中心,如果鼠标
// 所在屏幕为B,则在移动窗口位置时又会根据B的缩放比重新设置窗口大小,窗口将变为:
// 400x400,将形成一个循环。。。
if (!d->mouseMoved) {
setDisplayPosition(displayPosition());
}

QDialog::showEvent(event);
}

DAbstractDialog::DAbstractDialog(DAbstractDialogPrivate &dd, QWidget *parent):
QDialog(parent),
DObject(dd)
Expand Down
1 change: 1 addition & 0 deletions src/widgets/dabstractdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public Q_SLOTS:
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
void showEvent(QShowEvent *event) override;

protected:
DAbstractDialog(DAbstractDialogPrivate &dd, QWidget *parent = 0);
Expand Down

0 comments on commit 320d896

Please sign in to comment.