处理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"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -727,6 +727,7 @@
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">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> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>

View File

@ -13,6 +13,13 @@ ConnectionDialog::ConnectionDialog(QWidget *parent)
, m_pMainWindow(nullptr) , m_pMainWindow(nullptr)
{ {
ui->setupUi(this); 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(); initialize();
} }

View File

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

View File

@ -11,6 +11,13 @@ MessageDialog::MessageDialog(QWidget *parent)
//setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);//去掉关闭按钮 //setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);//去掉关闭按钮
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);//去掉关闭按钮和图标 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()); //不可缩放 setFixedSize(width(), height()); //不可缩放
connect(ui->btnConfrim, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm())); connect(ui->btnConfrim, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm()));

View File

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