[Qt-interest] QPushButton as delegate widget in a QTableView?

Robert Hairgrove evorgriahr at hispeed.ch
Fri Feb 18 22:54:30 CET 2011


On Fri, 2011-02-18 at 17:56 +0100, R. Reucher wrote:
> On Friday 18 February 2011 17:48, evorgriahr at hispeed.ch wrote:
> > ...
> > What would be the best approach for doing this? I could put the buttons
> > outside of the table view, but I think from a GUI design point of view
> > it would be better if they were displayed directly with the row being
> > edited. Could I just add these buttons as children of the table view's
> > client window, or scroll area, and get the geometry and position of the
> > cell at the end of the row in order to line them up with the data being
> > edited?
> How about using a QTableWidget (inherits QTableView) and to use 
> QTableWidget::setCellWidget() for the additional column?!
> 
> HTH, René

Thanks, René and Karl, for setting me on the right track. However,
looking at the source code for QTableWidget, I saw that
QTableWidget::setCellWidget() merely calls this base class function:

QAbstractItemView::setIndexWidget(const QModelIndex &index, 
   QWidget *widget)

which does the real work. So I will stay with the QTableView and try
that function.

I really like working with QTableView because it is so much more
flexible than QTableWidget ... you can choose your own model, and that
isn't possible with QTableWidget.




More information about the Qt-interest-old mailing list