Qt-interest Archive, December 2007
Attaching menu to table items
Message 1 in thread
Hello all,
I want to attach a context menu to items on my table so that the user
can right click the items and get at context menu that acts over the
item.
Well, as far as I understood the docs you cannot attach it to the item
itself but you can attach it to the table.
To attach it to the table, I need to redefine the contextMenuEvent of
the table. My table was created on designer, so to redefine this
method, do I need to subclass it, redefine the method and add it
manually to the Ui, or is there any better alternative?
Cheers,
--
[ signature omitted ]
Message 2 in thread
On 27.12.07 13:15:29, Paulo J. Matos wrote:
> Hello all,
>
> I want to attach a context menu to items on my table so that the user
> can right click the items and get at context menu that acts over the
> item.
> Well, as far as I understood the docs you cannot attach it to the item
> itself but you can attach it to the table.
> To attach it to the table, I need to redefine the contextMenuEvent of
> the table. My table was created on designer, so to redefine this
> method, do I need to subclass it, redefine the method and add it
> manually to the Ui, or is there any better alternative?
Check the designer manual, either use the promoting feature or create a
widget plugin with your QTableView subclass.
Andreas
--
[ signature omitted ]
Message 3 in thread
On Thursday 27 December 2007 14:15:29 Paulo J. Matos wrote:
> Hello all,
>
> I want to attach a context menu to items on my table so that the user
> can right click the items and get at context menu that acts over the
> item.
> Well, as far as I understood the docs you cannot attach it to the item
> itself but you can attach it to the table.
> To attach it to the table, I need to redefine the contextMenuEvent of
> the table. My table was created on designer, so to redefine this
> method, do I need to subclass it, redefine the method and add it
> manually to the Ui, or is there any better alternative?
>
> Cheers,
The best way is to
table->setContextMenuPolicy(Qt::CustomContextMenu);
then connect to this signal
void QWidget::customContextMenuRequested ( const QPoint & pos )
And in your slot get the index under pos (table->indexAt(pos)) and then create
and show your menu for the index at pos.
-Benjamin Meyer
--
[ signature omitted ]