KExtendableItemDelegate Class
This delegate makes it possible to display an arbitrary QWidget ("extender") that spans all columns below a line of items. More...
Header: | #include <KExtendableItemDelegate> |
CMake: | find_package(KF6 REQUIRED COMPONENTS ItemViews) target_link_libraries(mytarget PRIVATE KF6::ItemViews) |
Since: | 4.1 |
Inherits: | QStyledItemDelegate |
Public Types
enum | auxDataRoles { ShowExtensionIndicatorRole } |
Public Functions
KExtendableItemDelegate(QAbstractItemView *parent) | |
void | contractAll() |
void | contractItem(const QModelIndex &index) |
void | extendItem(QWidget *extender, const QModelIndex &index) |
bool | isExtended(const QModelIndex &index) const |
virtual void | updateExtenderGeometry(QWidget *extender, const QStyleOptionViewItem &option, const QModelIndex &index) const |
Reimplemented Public Functions
virtual void | paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override |
virtual QSize | sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override |
Signals
void | extenderCreated(QWidget *extender, const QModelIndex &index) |
void | extenderDestroyed(QWidget *extender, const QModelIndex &index) |
Protected Functions
QPixmap | contractPixmap() |
QPixmap | extendPixmap() |
QRect | extenderRect(QWidget *extender, const QStyleOptionViewItem &option, const QModelIndex &index) const |
void | setContractPixmap(const QPixmap &pixmap) |
void | setExtendPixmap(const QPixmap &pixmap) |
Detailed Description
The extender will logically belong to a column in the row above it.
It is your responsibility to devise a way to trigger extension and contraction of items, by calling extendItem() and contractItem(). You can e.g. reimplement itemActivated() and similar functions.
Warning: extendItem() reparents the provided widget extender to the viewport of the itemview it belongs to. The extender is destroyed when you call contractItem() for the associated index. If you fail to do that and the associated item gets deleted you're in trouble. It remains as a visible artefact in your treeview. Additionally when closing your application you get an assertion failure from KExtendableItemDelegate. Make sure that you always call contractItem for indices before you delete them.
Member Type Documentation
enum KExtendableItemDelegate::auxDataRoles
Constant | Value |
---|---|
KExtendableItemDelegate::ShowExtensionIndicatorRole | Qt::UserRole + 200 |
Member Function Documentation
KExtendableItemDelegate::KExtendableItemDelegate(QAbstractItemView *parent)
Create a new KExtendableItemDelegate that belongs to parent. In contrast to generic QAbstractItemDelegates, an instance of this class can only ever be the delegate for one instance of af QAbstractItemView subclass.
void KExtendableItemDelegate::contractAll()
Close all extenders and delete all extender widgets.
void KExtendableItemDelegate::contractItem(const QModelIndex &index)
Remove the extender of item at index from the view. The extender widget will be deleted.
[protected]
QPixmap KExtendableItemDelegate::contractPixmap()
Return the pixmap that is displayed to contract an item.
See also setContractPixmap().
void KExtendableItemDelegate::extendItem(QWidget *extender, const QModelIndex &index)
Insert the extender for item at index into the view. If you need a parent for the extender at construction time, use the itemview's viewport(). The delegate takes ownership of the extender; the extender will also be reparented and resized to the viewport.
[protected]
QPixmap KExtendableItemDelegate::extendPixmap()
Return the pixmap that is displayed to extend an item.
See also setExtendPixmap().
[signal]
void KExtendableItemDelegate::extenderCreated(QWidget *extender, const QModelIndex &index)
This signal indicates that the item at index was extended with extender.
[signal]
void KExtendableItemDelegate::extenderDestroyed(QWidget *extender, const QModelIndex &index)
This signal indicates that the extender belonging to index has emitted the destroyed() signal.
[protected]
QRect KExtendableItemDelegate::extenderRect(QWidget *extender, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplement this function to fine-tune the position of the extender. option.rect will be a rectangle that is as wide as the viewport and as high as the usual item height plus the extender size hint's height. Its upper left corner will be at the upper left corner of the usual item. You can place the returned rectangle of this function anywhere inside that area.
bool KExtendableItemDelegate::isExtended(const QModelIndex &index) const
Return whether there is an extender that belongs to index.
[override virtual]
void KExtendableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplements: QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const.
Re-implemented for internal reasons. API not affected.
[protected]
void KExtendableItemDelegate::setContractPixmap(const QPixmap &pixmap)
The pixmap that is displayed to contract an item. pixmap must have the same size as the pixmap in setExtendPixmap.
See also contractPixmap().
[protected]
void KExtendableItemDelegate::setExtendPixmap(const QPixmap &pixmap)
The pixmap that is displayed to extend an item. pixmap must have the same size as the pixmap in setContractPixmap.
See also extendPixmap().
[override virtual]
QSize KExtendableItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplements: QStyledItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const.
Re-implemented for internal reasons. API not affected.
[virtual]
void KExtendableItemDelegate::updateExtenderGeometry(QWidget *extender, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplement this function to adjust the internal geometry of the extender. The external geometry of the extender will be set by the delegate.