How to control the position of QDialog?

吃可爱长大的小学妹 提交于 2019-12-10 15:33:24

问题


Is there any easy way to open the Qt dialogs in the same position as they were the last time the application was open ?
i.e. preserve position of dialogs between application sessions ?

By easy way I mean not to have manually write the window position in file, and then read :)


回答1:


You can use the QSettings class to achieve this. It's an abstraction class that allow your applications to store its settings in order to retrieve them at next launch.

Save settings:

QSettings settings("ValueName",  "Value");

Read settings:

QString v = settings.value("ValueName");



回答2:


Use QSettings along with QWidget::restoreGeometry() and QWidget::saveGeometry().




回答3:


Better to save dialog->pos(), dialog->size(), dialog->isMaximized(), cause dialog->saveGeometry() doesn't maximize the window.

QSettings is the preffered way to save configuration



来源:https://stackoverflow.com/questions/1538425/how-to-control-the-position-of-qdialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!