
Originally Posted by
gadnio
So, how the hell can i swap/move columns without iterating through all the items and swapping text as a mad one (that is stupid and slow enough, i want the operation to be faster).
First of all, try disabling updates (using QWidget::setUpdatesEnabled()) while you switch columns. This should reduce the flicker.
Another way you could try requires subclassing QListViewItem. You will also need a mapping that maps logical columns (those which you use in your program) to physical ones (those that are visible in the view). This map should be shared among all items.
Now YourViewItem::paintCell() should be somthing like this:
void YourViewItem
::paintCell ( QPainter * p,
const QColorGroup
& cg,
int column,
int width,
int align
) {
QListViewItem::paintCell( p, cg, _map[ column ], width, align );
}
void YourViewItem::paintCell ( QPainter * p, const QColorGroup& cg, int column, int width, int align )
{
QListViewItem::paintCell( p, cg, _map[ column ], width, align );
}
To copy to clipboard, switch view to plain text mode
Probably you will have to change other methods too (AFAIR similar solution was discussed at QtForum).
Now if you want to switch columns, all you have to do is to update the map and redraw QListView contents.
You could also experiment with drag & drop mechanism (something tells me that you can use it to switch columns, but I'm not sure if it works).
Bookmarks