PDA

View Full Version : inheriting from QHeaderView disable QTableView SortingEnable ?



rastafaryd
1st June 2010, 21:02
Hi all,

I would like to create a context menu on my column table header, for this i've seen i need to inherit from QHeaderView and write something for contextMenuEvent.
But using even the simplest inherited class would cause me problem.

here is the simplest class :


#include <QHeaderView>

class columnHeaderView : public QHeaderView
{
Q_OBJECT

public :
columnHeaderView( Qt::Orientation p_orientation, QWidget *p_pere ):QHeaderView( p_orientation, p_pere )
{


}

} ;

and now if i do this :




view->setHorizontalHeader(new columnHeaderView( Qt::Horizontal, view )) ;
view->setSortingEnabled(true);

if i don't change the horizontalheader, then i can click on column headers and sort them, but i can't anymore after putting my inherited class....

do you have any comment on this please ?

high_flyer
2nd June 2010, 09:30
in the even handler you overridden, you have to call the event handler for QHeaderView .

rastafaryd
2nd June 2010, 13:59
The Thing is i didn't override any event, you can see it on the columnHeaderView above. i just wrote the constructor

CeeKey
2nd June 2010, 15:09
If you want to use your own QHeaderView, you have to set this feature programmatically. So if you would like to enable sorting, insert following line in the constructor of columnHeaderView :


setClickable(true);

QTableView set this for you if you do not change the HeaderView!

rastafaryd
2nd June 2010, 18:09
thanks it works fine :)