在调整窗口或拆分器大小时更改表格列宽度

发布于 2024-08-26 14:17:22 字数 149 浏览 5 评论 0原文

考虑有一个 QTablWidget 和一个 QTextEdit。它们都处于水平 QSplitte 中。让 QTable 小部件有 2 列。

问题是在通过用鼠标移动分隔符进行调整大小操作时调整表格列的宽度。是否有任何选项可以使列与表同步调整大小?

谢谢。

Consider there is a QTablWidget and a QTextEdit. Both of them are in a horisontal QSplitte. Let the QTable widget has 2 columns.

The problem is to resize the table columns' width as you do resize operation by moving the splitter with mouse. Are there any options to may colums to be resized synchornosly with the table?

Thanks.

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

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

发布评论

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

评论(1

錯遇了你 2024-09-02 14:17:22
QHeaderView *header = ui->tableWidget->horizontalHeader();
header->setResizeMode(QHeaderView::Stretch);

这段代码将 ui->tableWidget 的所有列设置为相等宽度并让它自动改变。
看看文档中的 QHeaderView 描述,您可以使用此 API 对表列执行几乎任何您能想象到的操作。

遗憾的是,如果您需要关系列宽度不相等,则无法设置任何拉伸因子或其他东西,但您仍然可以在标题的 geometriesChanged 触发时重新实现 sizeHint() 或调整部分大小。

QHeaderView *header = ui->tableWidget->horizontalHeader();
header->setResizeMode(QHeaderView::Stretch);

This code sets all columns of ui->tableWidget to equal width and let it change automatically.
And take a look on QHeaderView description in docs, you can do almost anything you can imagine with table columns with this API.

Sad, but you can't set any stretch factor or smth., if you need relational column widths not to be equal, but you still can reimplement sizeHint() or resize sections when header's geometriesChanged fires.

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