QModelRoleData 类保持角色和与该角色关联的数据。 更多...
头: | #include <QModelRoleData> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Since: | Qt 6.0 |
QModelRoleData (int role ) | |
void | clearData () |
QVariant & | data () |
const QVariant & | data () const |
int | role () const |
void | setData (T && value ) |
QModelRoleData objects store an item role (which is a value from the Qt::ItemDataRole enumeration, or an arbitrary integer for a custom role) as well as the data associated with that role.
A QModelRoleData object is typically created by views or delegates, setting which role they want to fetch the data for. The object is then passed to models (see QAbstractItemModel::multiData ()), which populate the data corresponding to the role stored. Finally, the view visualizes the data retrieved from the model.
另请参阅 模型/视图编程 and QModelRoleDataSpan .
[explicit noexcept]
QModelRoleData::
QModelRoleData
(
int
role
)
Constructs a QModelRoleData object for the given role .
另请参阅 Qt::ItemDataRole .
[noexcept]
void
QModelRoleData::
clearData
()
Clears the data held by this object. Note that the role is unchanged; only the data is cleared.
另请参阅 data ().
[constexpr noexcept]
QVariant
&QModelRoleData::
data
()
Returns the data held by this object as a modifiable reference.
另请参阅 setData ().
[constexpr noexcept]
const
QVariant
&QModelRoleData::
data
() const
Returns the data held by this object.
另请参阅 setData ().
[constexpr noexcept]
int
QModelRoleData::
role
() const
Returns the role held by this object.
另请参阅 Qt::ItemDataRole .
[constexpr noexcept(...)]
template <typename T>
void
QModelRoleData::
setData
(
T
&&
value
)
Sets the data held by this object to value . value must be of a datatype which can be stored in a QVariant .
注意: This function does not throw any exception when "noexcept(m_data.setValue(std::forward<T>(value)))" is true.
另请参阅 data (), clearData (),和 Q_DECLARE_METATYPE .