Custom QStyledItemDelegate (QToolButton) - hovering instead of edit
Hello folks,
I've got a little issue with my custom StyledItemDelegate. I have got a list view where I want to add a remove button on the first column. This works pretty good but it is just visible in edit mode, but I want to have it visible when I hover the row.
Can anyone give me a hint how to implement this?
buttondelegate.h
Code:
#ifndef BUTTONDELEGATE_H_
#define BUTTONDELEGATE_H_
#include <QStyledItemDelegate>
class ButtonDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
virtual void setEditorData(
virtual void setModelData(
virtual void updateEditorGeometry(
};
#endif
Code:
#include "buttondelegate.h"
#include <QToolButton>
#include <QApplication>
//-----------------------------------------------------------------------------
ButtonDelegate
::ButtonDelegate(QObject *aParent
) : QStyledItemDelegate(aParent)
{
}
//-----------------------------------------------------------------------------
QWidget *ButtonDelegate
::createEditor( {
if (aIndex.column() == 0) {
btn->setText("...");
//btn->setAutoRaise(true);
btn->setCheckable(true);
btn
->setFixedSize
(QSize(16,
16));
return btn;
}
return NULL;
}
//-----------------------------------------------------------------------------
void ButtonDelegate::setEditorData(
{
}
//-----------------------------------------------------------------------------
void ButtonDelegate::setModelData(
{
//QApplication::processEvents();
if (static_cast<QToolButton*>(aEditor)->isChecked())
aModel->removeRow(aIndex.row());
}
//-----------------------------------------------------------------------------
void ButtonDelegate::updateEditorGeometry(
{
aEditor->setGeometry(aOption.rect);
}
And yes I have searched on the forum and found some things but they didn't help.
Kind regards,
Sven
Re: Custom QStyledItemDelegate (QToolButton) - hovering instead of edit
You can throw away your implementation because it's wrong and search the forum again. This question has already been answered lots of times. So far you made an editor for your item.