PDA

View Full Version : QTableWidget top row won't update



kiss-o-matic
22nd June 2010, 02:36
This problem is driving me nuts, and it's happened in several of my applications. I think I wrote this to qt-interest but a search there says otherwise. I found this thread (http://lists.trolltech.com/qt-jambi-interest/2007-01/msg00020.html) in my searching, which didn't exactly help but it sounds similar. Mine is a bit weirder though.

The problem is my QTableWidget's top row will not update until a user-driven event. I'm explicitely calling update() every time I add a row or change the contents of a QTableWidgeteItem. For safe mesure I even added QTimer that calles update() every 500 milliseconds. It will not update. The kicker is, it's the top row only, and I've seen it in a few projects.

I'm not setting setUpdatesEnabled( false ). The widget is definitely not hidden.

The project is too big to post, but the idea is below. There's really no "magic" going on anywhere (that I know of). One really ghetto way I got around it in one application was to make a "dummy row" that had enough height to take the brunt of the non-repainting. The only way I can get it to repaint is some type of user input. Resize the entire dialog, Click & Drag the mouse over each column of row 0, etc.



mytable::mytable( int r, int c, QWidget* parent ) : QTableWidget( r, c, parent )
{
QStringList headers;
headers >> "h1" << "h2"; //etc
setHorizontalHeaderLabels( headers );
setShowGrid( false );
setFocusPolicy( Qt::NoFocus );
setSelectionMode( QAbstractItemView::NoSelection );
setEditTriggers( QAbstractItemView::NoEditTriggers );
verticalHeader()->hide();
verticalHeader()->setDefaultSectionSize( fontMetrics().lineSpacing() + 2 );
// hide the last column
horizontalHeader()->hideSection( columnCount() - 1 );
}

myview::myview( QWidget* parent ) : QDialog( parent )
{
mytable* table = new mytable( 0, 10, this );
mytable->setStyle( new QPlastiqueStyle ); // oxygen table is crap
}

int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
myview* view = new myview();
view->show();
return app.exec();
}


As per before, nothing too crazy. For now, this really, really tacky fix works. I call it whenever I do anything to row 0.



void mytable::crap_paint_hack()
{
insertRow( 0 );
removeRow( 0 );
}