PDA

View Full Version : Adding button to QTableview .



riarioriu3
2nd August 2012, 13:38
I have created one table by using QTableview and QAbstractTableModel .
In one of the cell i want to add one help button (right corner of that cell ).

Is there any way to achieve the above one ?

spirit
2nd August 2012, 13:40
use QItemDelegate.

riarioriu3
2nd August 2012, 13:44
can you please give a small example on this ?

spirit
2nd August 2012, 13:46
How to use delegates (http://qt-project.org/doc/qt-4.8/model-view-programming.html#delegate-classes).

riarioriu3
4th August 2012, 19:23
but through QItemDelegate we can only display the widget during editing the cell..
Is there any way to display it permanently ?

spirit
4th August 2012, 21:39
Well, you can use QAbstractItemView::openPersistentEditor, but it can "slow down" your view if there are a lot of data.
I would suggest to grab an editor using QPixmap::grabWidget or even better to render it using QWidget::render in the item's delegate QItemDelegate::paint method.

riarioriu3
5th August 2012, 15:51
thank you .. i got the concept ..But when i am using the delegate , that delegate overlapes on the existing data ..
can you please give any idea on this ?

moijhd
8th July 2013, 10:40
Hi,

I am trying to "to render it using QWidget::render in the item's delegate QItemDelegate::paint method".

I took the Qt example "SpinBoxDelegate" and I try to display a QToolButton :



void SpinBoxDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 1)
{
QToolButton* widget = new QToolButton();
widget->setText("Click me");
widget->render( painter );
}
else
{
QItemDelegate::paint(painter, option, index);
}
}


But nothing is displayed...

How am I supposed to create the widget ?

frsdot
19th October 2013, 20:28
Hello,
i have similar issue ( displaying button in tableview), can you pls let me know how you fixed this ?
Thank you.

vikuseth
21st October 2013, 07:48
Just create one button image over the place you want to put button and add an event to that image which works like a button .