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 :

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 :

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.

2 thoughts on “contextmenu in QTableView

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.