我拖放一个表视图小部件 (Qt)。填充元素后如何调整其大小?

发布于 2024-11-26 06:13:28 字数 623 浏览 0 评论 0原文

我正在使用 Ubuntu/c++ 语言工作。

我有以下 QTable:

 ui1->tableView_->setVisible(false);
 QStandardItemModel *itemmodel_ = new QStandardItemModel(0,1);
 itemmodel_->setHeaderData(0, Qt::Horizontal, tr("File"));
  ui1->tableView_->setModel(itemmodel_);
//.. add new rows in the table

  ui1->tableView_->resizeColumnsToContents();
              ui1->tableView_->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);

  ui1->tableView_plugin->setVisible(true);

运行应用程序后,表的大小没有调整。我哪里错了?如何解决问题?

还有一个问题:如何选择一整行以便在按下删除按钮后将其删除。

欣赏。 谢谢

I am working in Ubuntu/c++ language.

I have the following QTable :

 ui1->tableView_->setVisible(false);
 QStandardItemModel *itemmodel_ = new QStandardItemModel(0,1);
 itemmodel_->setHeaderData(0, Qt::Horizontal, tr("File"));
  ui1->tableView_->setModel(itemmodel_);
//.. add new rows in the table

  ui1->tableView_->resizeColumnsToContents();
              ui1->tableView_->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);

  ui1->tableView_plugin->setVisible(true);

After running the application the table is not resized. Where am I wrong? How to solve the problem?

And one more question: how to select an entire row in order to delete it after pressing a delete push button.

Appreciate.
THX

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

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

发布评论

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

评论(1

故人的歌 2024-12-03 06:13:28

看来您没有将 TableView 添加到任何布局中。您需要将其添加到表单中的任何布局中。例如:

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(tableView);

布局是小部件的容器。其目的是为其小部件添加定位和调整大小规则。例如 QVBoxLayout 只是垂直排列小部件。您可以将布局与其他布局组合。因此,您可以更简单地构建复杂的 UI 设计(通过调整大小支持)。有关更多信息,您可以查看此文档本文档

It seems like you didn't add your TableView to any layout. You need to add it to any layout in your form. For example:

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(tableView);

Layout is a container for widgets. It purpose is adding positioning and resizing rules for its widgets. For example QVBoxLayout simply arranges widgets vertically. You can combine layouts with another layouts. So you can build complex UI designs simpler (with resize support). For further information you can check this document and this document

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