本文内容
O3DE UI 表视图组件
使用 table view 组件以表格格式显示多列结构化数据。默认情况下,此组件使用可排序列和“斑马条带化”(其中行的背景色交替)来帮助您创建易于阅读、可扫描和可排序的数据表示。
注意:AzQtComponents::TableView
实际上派生自QTreeView
,而不是QTableView
,以提供对行大小的更多自定义。
Basic table view
创建简单的日志记录表视图。
注意:如果表格视图与 树视图 结合使用,则可能需要使用 setAlternatingRowColors(false) 函数在其中一个小部件中关闭斑马纹条带化。
示例
#include <AzQtComponents/Components/Widgets/TableView.h>
#include <AzToolsFramework/UI/Logging/LogTableModel.h>
#include <AzToolsFramework/UI/Logging/LogLine.h>
#include <QDateTime>
// Create a log table model for this example.
auto logModel = new AzToolsFramework::Logging::LogTableModel(this);
// Create the table view.
auto tableView = new AzQtComponents::TableView(parent);
// Set the model for the table.
tableView->setModel(logModel);
// Add a few lines of sample data.
logModel->AppendLine(
AzToolsFramework::Logging::LogLine(
"An informative message for debugging purposes.",
"Window",
AzToolsFramework::Logging::LogLine::TYPE_MESSAGE,
QDateTime::currentMSecsSinceEpoch()));
logModel->AppendLine(
AzToolsFramework::Logging::LogLine(
"A warning message for things that may not have gone as expected.",
"Window",
AzToolsFramework::Logging::LogLine::TYPE_WARNING,
QDateTime::currentMSecsSinceEpoch()));
logModel->AppendLine(
AzToolsFramework::Logging::LogLine(
"Critical error message, something went wrong.",
"Window",
AzToolsFramework::Logging::LogLine::TYPE_ERROR,
QDateTime::currentMSecsSinceEpoch()));
C++ API 参考
有关 table view API 的详细信息,请参阅 O3DE UI 扩展 C++ API 参考 中的以下主题:
相关的 Qt 文档包括以下主题: