[Qt-interest] Questions about table view and item delegates

Christian Gagneraud cgagneraud at techworks.ie
Fri Jan 22 13:30:36 CET 2010


Hi all,

I'm using a table view with spinbox delegate, I've based my code on 
http://doc.trolltech.com/4.6/itemviews-spinboxdelegate.html.

I'm using SDK 2009.01 on Fedora 12.

I've re-used "as is" spinboxdelegate.{cpp,h}, and my main() looks like 
this:

int main(int argc, char *argv[])
{
     QApplication a(argc, argv);
     MainWindow w;

     /* Set-up the schedule table using spinbox delegate */
     QTableWidget* widget = w.findChild<QTableWidget*>("tableSchedule");
     int nrows = widget->rowCount();
     int ncols = widget->columnCount();
     QStandardItemModel model(nrows, ncols);
     QTableView* view = widget;
     view->setModel(&model);
     SpinBoxDelegate delegate;
     view->setItemDelegate(&delegate);
     for (int row = 0; row < nrows; ++row) {
              for (int column = 0; column < ncols; ++column) {
                  QModelIndex index = model.index(row, column, 
QModelIndex());
                  model.setData(index, QVariant(0));
              }
          }

     w.show();
     return a.exec();
}

The only noticeable difference (for me) between the example and my 
(simple) app is that the table view is embedded within a form designed 
with QtDesigner/QtCreator. As a consequence I use Mainwindow.show() 
instead of TableView.show() and I got the pointer to my QTableView via 
findChild().

Problem 1:
When I insert data into the model, they are not shown up in the view. 
For example, I'm expected to get my table filled with zeros, but 
instead I got an empty table. If i execute the unmodified example, it 
works as expected!

Problem 2:
I'm using a grid layout for my widgets, when I resize the window, the 
table widget is resized and fill up all the space, but the row and 
column sizes don't change. I would like to have the columns width and 
the rows height to spread all the available space.
I couldn't find so far a way to get this behaviour. Is it possible to 
get this kind of behaviour, if so, can anyone point me to some example 
code?

Problem 3:
When the user select several cells, or a whole column or row, I would 
like that changing the value of one of these cells change the value of 
all the selected cells. Again I didn't find any documentation on how 
to do this. Any help appreciated on that matter too.


Regards,
Chris



More information about the Qt-interest-old mailing list