[Qt-interest] QTableWidget change columncount on resize
Teaburon
teaburon at googlemail.com
Sun Jun 27 13:50:09 CEST 2010
Hello!
I have subclassed QTableWidget for my current project. The widget holds
quadratic cells of the same size and each cell contains one character. The
visible items are stored in a QList<T> myItems. Now I want the table to
change its columnCount on a resize, so that the cellsize stays the same and
more (or less) items are visible if the user resizes the table. I therefore
implemented resizeEvent like this:
void MyTableWidget::resizeEvent(QResizeEvent *e) {
if (columnCount() > 0 ) {
int colC = e->size().width() / columnWidth(0);
int rowC = myItems.size() / colC;
setColumnCount(colC);
setRowCount(rowC);
row = col = 0;
for(int i = 0; i < myItems.size(); ++i){
MyItem * c = new MyItem(myItems.at(i));
setItem(row,col,c);
col++;
if (col % colC == 0) {
col = 0;
row++;
}
myItems.replace(i, *c);
}
}
QWidget::resizeEvent(e);
}
This works nearly the way I want, but it is slow, because of the copy action
and since myItems is very large (>2k entries)... Is there any way to achieve
this behavior without copying the items like I did?
Any advice on how to make this faster would be great!
Greetings Teaburon.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100627/77c0c667/attachment.html
More information about the Qt-interest-old
mailing list