PDA

View Full Version : Separating QHeaderView from QTableView



Jimmy2775
22nd November 2006, 00:47
I am using a QTableView to display data. The problem I've encountered is that the table has so many rows, it is possible for users to scroll down the table so that the column headers go out of view, which is not good.

My solution for this is to move the table's QHeaderView outside the QTableView. The table sits inside a QScrollArea, so I want to move the header above the QScrollArea. I've done it this way:


QHeaderView* iHeaderView = mTableView->horizontalHeader();
iHeaderView->setParent( headerPlaceHolder );
In the above code, headerPlaceHolder is a QFrame that is positioned where I want the header to be. If I run the code, the grid is drawn without the header, but the header does not appear in the placeholder frame. I've tried to resolve this in two ways:
I call show() on the QHeaderView.
I add a layout to the placeholder frame and call addWidget(), passing in the QHeaderView.Either way has the same result - the header appears where I want it to, but the grid is drawn with space allotted for the header. Does anyone know how I could eliminate this space? I've looked through the QTableView and QAbstractItemView code but I can't seem to find the problem - I'm not even sure what to look for.

Also, has anyone tried anything similar to what I'm trying to do here? I'm not sure if I'm taking the right approach to this.

Jimmy

jpn
22nd November 2006, 07:47
You will have to look into QTableView::paintEvent() sources, I'm afraid. QTableView paints itself according to the offsets and coords retrieved from the header views.