PDA

View Full Version : QTableView with custom QHeaderView



xbase
13th September 2007, 17:14
hi,

is there a way to write a custom table header which takes into account grouped collumns? say i have colums like Input1, Input2, Input3, and Output1, Output2, which should be grouped by Inputs and Outputs. the table header should then have 2 rows and look like this:
_________________________________________
|________Inputs________|______Outputs_____|
| Input1 | Input2 | Input3 | Output1 | Output2 |

clicking at Inputs should select all Input collums, clicking on Input1 only Input1 ans so on.

does anyone have an idea how this could be done.

greetings.

xbase
14th September 2007, 09:41
nobody i guess. :crying:

wysota
14th September 2007, 09:50
Yes, there is a way :) You have to implement your own QHeaderView subclass and implement the functionality you want.

xbase
14th September 2007, 10:13
yeah right but how exactly? i guess i have to rewrite the whole drawing capabilitys like paintEvent and paintSection. any idea where to start?

wysota
14th September 2007, 10:31
You'll have to implement half of the functionality from the abstract view. Things like index positions, etc. Practically all you can take from QHeaderView is the inheritance, so that you can use it with a table view. But it might be inpractical (you'll have to reimplement some of the table view functionality as well). It might be easier to instead implement your own header (for example composited from two or more QHeaderView instances) and couple it with the table.

xbase
14th September 2007, 11:34
i have started with reimplementing paintEvent ( QPaintEvent * event ) but when i try to create a QPainter as shown in the documentation the console says:

QPainter::begin: Widget painting can only begin as a result of a paintEvent

but it is inside paint event.

code

HeaderView::HeaderView(Qt::Orientation orientation, QWidget * parent) : QHeaderView(orientation, parent)
{
}


void HeaderView::paintEvent ( QPaintEvent * event )
{
QPainter painter(this);
painter.drawRect(event->rect());
}

any idea?

xbase
14th September 2007, 14:21
ok this problem is solved. used

QPainter painter(viewport());

instead.

will try to reimplement the QHeaderView. if anyone has an idea on how this could be done otherwhise let me know please. i thought letting table items be tables of its own so that one would automaticly have more headers. the only problem is then how to sort and how to design in model/view architekture. any advices?

tnx