PDA

View Full Version : Under the delegate the data are visible



Mad Max
15th February 2006, 06:28
Hi,

How I can get rid of it?

zlatko
15th February 2006, 09:11
Can you tell us actually how do you get this?

Mad Max
15th February 2006, 10:33
Can you tell us actually how do you get this?
:) Yes, of course... I use a delegate which give a possibility to edit the data of the item of treeWidget. The widget of the editing (QSlider) is visible always. When editing through this widget under it the data are visible.

Mad Max
15th February 2006, 18:58
Can anyone help me?

wysota
15th February 2006, 19:04
We'd have to see your modifications to the delegate.

Mad Max
15th February 2006, 19:25
We'd have to see your modifications to the delegate.
Ok. It is a declaration:


class QLayerListDelegate : public QItemDelegate
{
Q_OBJECT

public:
explicit QLayerListDelegate(QObject *parent = 0)
: QItemDelegate(parent) { ; };

virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
private slots:
void emitCommitData();
};


It is extractions from methods which relate to it:
from createEditor


...
} else if (index.column() == 1) {
TextSlider * slider = new TextSlider(2, parent);
connect(slider, SIGNAL(valueChanged( float )), this, SLOT(emitCommitData()));
ret = dynamic_cast<QWidget*>(slider);
} else if (index.column() == 2) {
...


from setEditorData


...
} else if (index.column() == 1) {
TextSlider * slider = qobject_cast<TextSlider*>(editor);
if ( !slider )
return;
slider->setValue(index.model()->data(index).toDouble());
} else if (index.column() == 2) {
...


from setModelData


...
} else if (index.column() == 1) {
TextSlider * slider = qobject_cast<TextSlider*>(editor);
if ( !slider )
return;

model->setData(index, slider->value());
} else if (index.column() == 2) {
...

wysota
15th February 2006, 19:33
You have to reimplement paint() method to leave the cell blank if you use a persistant editor for it.

orb9
15th February 2006, 21:28
You also could try

setAutoFillBackground ( true );
on the editor widget if implementing paintEvent() is not needed for other stuff.

Mad Max
16th February 2006, 12:36
Hi guys. Thanks for your answers.

You also could try

setAutoFillBackground ( true );
on the editor widget if implementing paintEvent() is not needed for other stuff.

I did thus. Yes, it has helped, but happen a new problem. When the item is selected the highlight is not visible under the editor (see the first attached image)


You have to reimplement paint() method to leave the cell blank if you use a persistant editor for it.

I did thus. I reimplemented paint() mathod:


void QLayerListDelegate::paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
if ( option.state & QStyle::State_Selected ) {
painter->fillRect(option.rect, QBrush(option.palette.highlight()));
} else {
painter->fillRect(option.rect, QBrush(option.palette.base()));
}
}


but the text in other column was gone :) (see the second attached image). What I can make so as it not happen?

wysota
16th February 2006, 12:56
but the text in other column was gone :) (see the second attached image). What I can make so as it not happen?


void QLayerListDelegate::paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
if(index.column()==3) return;
QStandardItemDelegate::paint(painter, option, index);
}

Mad Max
16th February 2006, 13:28
void QLayerListDelegate::paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
if(index.column()==3) return;
QStandardItemDelegate::paint(painter, option, index);
}

It do help! Thanks Wysota!