处理Linux下窗口位置显示不正确以及个边框丢失问题

This commit is contained in:
duanshengchao 2025-04-03 16:13:11 +08:00
parent 933f051bff
commit c83d215568
5 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.2, 2025-03-19T08:46:05. -->
<!-- Written by QtCreator 13.0.2, 2025-04-03T14:28:51. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -727,6 +727,7 @@
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/Code/CL-Softwares/Git/PowerModeler/build/Qt_MinGW_64_bit-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

View File

@ -13,6 +13,13 @@ ConnectionDialog::ConnectionDialog(QWidget *parent)
, m_pMainWindow(nullptr)
{
ui->setupUi(this);
if(QSysInfo::kernelType() == "linux")
{
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示并且最大、最小按钮不好关闭去边框后是简单的解决上述问题的方法
setWindowFlags(Qt::FramelessWindowHint);
setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;}");
}
setModal(true);
initialize();
}

View File

@ -146,14 +146,13 @@ void MainWindow::onActionTrigger_connect()
connect(m_pConnectionDialog, &ConnectionDialog::addConnection, this, &MainWindow::onSIG_addConnection);
}
/* int nX = this->geometry().x() + (this->width() - m_pConnectionDialog->width()) * 0.5;
int nY = this->geometry().y() + (this->height() - m_pConnectionDialog->height()) * 0.5;
m_pConnectionDialog->move(nX, nY);*/
QRect parentFrame = this->frameGeometry(); // 获取父窗口的完整几何信息(包含边框和标题栏),适用于快平台对其
int nX = parentFrame.x() + (parentFrame.width() - m_pConnectionDialog->width()) / 2;
int nY = parentFrame.y() + (parentFrame.height() - m_pConnectionDialog->height()) / 2;
m_pConnectionDialog->move(nX, nY);
m_pConnectionDialog->exec();
// int nX = this->geometry().x() + (this->width() - m_pConnectionDialog->width()) * 0.5;
// int nY = this->geometry().y() + (this->height() - m_pConnectionDialog->height()) * 0.5;
// m_pConnectionDialog->move(nX, nY);
QPoint centerPos = this->mapToGlobal(this->rect().center());
centerPos -= QPoint(m_pConnectionDialog->width()/2, m_pConnectionDialog->height()/2);
m_pConnectionDialog->move(centerPos);
m_pConnectionDialog->show();
}
void MainWindow::onActionTrigger_disconnect()
{

View File

@ -11,6 +11,13 @@ MessageDialog::MessageDialog(QWidget *parent)
//setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);//去掉关闭按钮
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);//去掉关闭按钮和图标
if(QSysInfo::kernelType() == "linux")
{
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示并且最大、最小按钮不好关闭去边框后是简单的解决上述问题的方法
setWindowFlags(Qt::FramelessWindowHint);
setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;}");
}
setFixedSize(width(), height()); //不可缩放
connect(ui->btnConfrim, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm()));

View File

@ -360,13 +360,13 @@
<widget class="QLabel" name="label_hostName">
<property name="minimumSize">
<size>
<width>91</width>
<width>106</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>91</width>
<width>106</width>
<height>21</height>
</size>
</property>