What can I do for my QtWidget-Program's Window correctly positioned on the screen?
-
First , My Program is made by QtWidget for Linux Desktop, with the X11 , it work perfectly. but if I turn My Ubuntu to Wayland, From a functional point of view, although it can also work normally, the positioning of its message popup window is messed up.
From the source code, what should I do so that when this program runs in the wayland environment, its sub-windows and key-triggered messages can be correctly positioned on the upper layer of the main program window?
-
@foghere2023 How do you show those messages?
See https://doc.qt.io/qt-6/qdialog.html#QDialog : if you provide parent to dialog constructor the dialog should be automatically centered on the parent. -
@jsulm yes , I have done , just like this, Each message window has a clear parent window defined:
it work well in x11,but wayland
void MainWindow::on_btnOpenSchema_clicked() { QString curPath=QDir::currentPath(); QString dlgTitle="打一个Schema文件"; QString filter = "schema文件(*.schema.yaml)"; QString aFileName=QFileDialog::getOpenFileName(this,dlgTitle,curPath,filter); if(aFileName.isEmpty()) return; if(!aFileName.contains(".schema.yaml")){ QMessageBox::information(this, "请选择 schema 文件", "请先择 schema 文件,带 schema 标识的文件!", QMessageBox::Ok,QMessageBox::NoButton); return;} disclick(true); dischange(true); bool ok = readSchema.openYamlByStream(aFileName); if(ok) QMessageBox::information(this,"提示消息","已成功读档!"); if(readSchema.getRamState()){ ui->labelCurrentData->setText("配置文件已装载!"); ui->labelCurrentData->setAlignment(Qt::AlignHCenter); ui->btnListenSchema->setEnabled(false); ui->btnListenDict->setEnabled(false); ui->labelCurrState->setText("已触发监听禁用"); } swapNum = readSchema.getLogicBits(); initSwitches(); iniCheckBox(); ui->btnSaveSchema->setEnabled(readSchema.getRamState()); readSchema.inihotKeys(); iniModelFromStringList(); }
-
This is the simplest Demo:
void MainWindow::on_pushButton_clicked() { QMessageBox::information(this,"提示消息","已成功读档!"); }
the key word【this】can't find his farther!
-
J JonB referenced this topic on
-
@foghere2023
I believe it has already been reported that you cannot move/position windows under Wayland, and I believe the only workaround is to use Xorg. Search this forum for similar posts. -
@foghere2023
Googleqt wayland move window
-
@jsulm Hi guys ,I find someone had the same problem as me:
The QDialog default position should locate at centered on top of the parent's top-level widget. But QDialog in Wayland shows on a random position. Even I try to use "move" to assign a specific position, it doesn't work.
-
According to the normal logic, the pop-up message prompt should be suspended on the upper layer of the parent window.
QMessageBox and some child Dialog cannot on top of its parent window in Wayland,this looks like Qwidget's bug.
What should i do ?
-
@foghere2023
See if it works under Xorg?
If so wait for it to work under Wayland at a future date, assuming it can? -
@JonB thank you guys, it works very well under Xorg,and I have test a simple Demo like is :
void MainWindow::on_pushButton_clicked() { QMessageBox::information(this,"提示消息","已成功读档!"); }
This Demo only have one line of command here for QMessageBox , I have spent all day for the workaround,I don't know this is my false or Qt-team‘s. :(
as your piont ,this is not my false ?
-
@foghere2023 hi,
It's neither. See the Wayland doc.
-
@SGaist So guys,Reading the docs is just too difficult for me, someone tell me to wait, because there is a day that Qwidget App's Popups and parent windows can locate correctly .
Is there any way we can get the program to work now?
-
Can someone help me?
-
Looking forward to friends repeating this bug
-
@foghere2023 please show some patience and allow at least 24 hours to pass before bumping your own thread. This is a voluntary driven forum and people may not live in the same timezone as you.
Weston is the reference implementation of a Wayland compositor.
As for your issue, the Wayland specification is explicit, windows cannot move themselves around the desktop.