有没有一种简单的方法可以恢复 Qt 中的小部件大小?

发布于 2024-07-16 14:43:21 字数 215 浏览 2 评论 0原文

我正在寻找一种在 Qt 应用程序中保留窗口大小的方法。

我已经看到可以对每个小部件使用以下方法:

saveGeometry()

但实际上,我不认为这是一种令人满意的方法。 有类似 setAutosaveGeometry(True) 的东西吗?

我特别寻找一种存储表列宽度的方法。

I'm looking for a way to preserve the size of windows in a Qt app.

I've seen that there is the possibility of using the following method for every widget:

saveGeometry()

But really, I don't find this a satisfactioning method. Is there something like setAutosaveGeometry(True)?

I'm especially looking for a way to store the widths of table columns.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

り繁华旳梦境 2024-07-23 14:43:21

QHeaderView 类还有两种方法用于在 QByteArray 中保存和恢复其状态:saveState()和restoreState()

表视图的标题可以通过horizo​​ntalHeader()和verticalHeader()方法访问。

The QHeaderView class also has two methods for saving and restoring it's state to and from a QByteArray: saveState()and restoreState()

A table view's headers are accessible via the horizontalHeader() and verticalHeader() methods.

献世佛 2024-07-23 14:43:21

saveGeometry 返回一个 QByteArray 值,您需要将其存储在某个地方。

示例:

void MainWindow::closeEvent(QCloseEvent *event){
    QSettings settings;

    settings.setValue("geometry", saveGeometry());
}

要读取几何图形,请调用restoreGeometry函数:

MainWindow::MainWindow(QWidget *parent):QMainWindow(parent) {
    [...]

    QSettings settings;

    restoreGeometry(settings.value("geometry").toByteArray());

    [...]
}

要了解有关窗口几何图形的更多信息,请阅读文档< /a>

saveGeometry returns a QByteArray value, you need to store it somewhere.

Example:

void MainWindow::closeEvent(QCloseEvent *event){
    QSettings settings;

    settings.setValue("geometry", saveGeometry());
}

For reading the geometry call the restoreGeometry function:

MainWindow::MainWindow(QWidget *parent):QMainWindow(parent) {
    [...]

    QSettings settings;

    restoreGeometry(settings.value("geometry").toByteArray());

    [...]
}

To learn more about window geometry please read the documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文