contextmenu in QTableView
Continue with my last post about QtableView tutorial (fill Qtableview with value), I try to create another post about how to create contextmenu in QtableView. With this tutorial, you can implementated contextmenu in other Widget in Qt like QtableWidget, QlistWidget and other. The basic idea how to create contextmenu in QtableView is like with contextmenu in QtableWidget, contextmenu in Qlistwidget and other.
We can add contextmenu in widget with change setContextMenuPolicy property with value Qt::CustomContextMenu. We can set contextmenu in QtableView with command :
tblv->setContextMenuPolicy(Qt::CustomContextMenu); connect(tblv, SIGNAL(customContextMenuRequested( const QPoint& )), this, SLOT(tablev_customContextMenu( const QPoint& )));
If we want to add contextmenu in QtableView header, we must get object from QtableView header and set contextmenu in that object. This is sample command how to implementated this :
//connect horizontal header QTableView with contextmenu horizontalHeader = tblv->horizontalHeader(); horizontalHeader->setContextMenuPolicy(Qt::CustomContextMenu); connect(horizontalHeader, SIGNAL(customContextMenuRequested( const QPoint& )), this, SLOT(tablev_customContextMenu( const QPoint& )));
This is output from QTableView tutorial create contextmenu in QtableView and contexmenu in QtableView Header :
You can download my full source code (create contextmenu in QtableView) from here.
wuihh.. mampir ke web programmer nih 🙂 sorry kalo komeng ane OOT ya mas 🙂
Good morning, QTableView was researching for a particular problem and could not find an answer, the problem is:
need to resize the scrollbar tableview, however, can not,
already tried to use the following code
QScrollBar scroll = * this-> tableView-> verticalScrollBar ();
scroll-> setFixeWidth (50);
it increases, but the view is cut tableview you have any suggestions?
thanks