我拖放一个表视图小部件 (Qt)。填充元素后如何调整其大小?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您没有将 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:
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