Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, June 2007
Capturing right-clicks in QTableWidget


Message 1 in thread

Hi -

I have an application using a QTableWidget, and I
would like to be able to respond to right-click events
on cells in the table (but not with a context menu). 
Ideally, I would like to get the QTableWidget to emit
a signal with the row and column of the cell that was
clicked on.  Any help would be much appreciated.

Thanks.
Bryan

--
 [ signature omitted ] 

Message 2 in thread

Bryan Thibodeau schrieb:
> I have an application using a QTableWidget, and I
> would like to be able to respond to right-click events
> on cells in the table (but not with a context menu). 
> Ideally, I would like to get the QTableWidget to emit
> a signal with the row and column of the cell that was
> clicked on.  Any help would be much appreciated.

As QTableWidget doesn't provide a cellRightClicked() signal, you should 
reimplement mousePressEvent() (or mouseReleaseEvent() if that fits you 
better) to do so, then you can hook up your actions there.

Martin

-- 
 [ signature omitted ] 

Message 3 in thread

There are a couple possible techniques you can use that come to mind:

   1. Use an event filter in the parent class that holds the
      QTableWidget.  This could capture the mouse right click events and
      the co-ordinates.  From there you can query the widget and find
      out which cell is involved (using QTableView::rowAt &
      QTableView::columntAt, for example)
   2. Derive from QTableWidget, your own widget which emits the signal. 
      Your derivation must extend ::mousePressEvent to use the technique
      in (1) to emit the signal with the cell.

HTH,
Susan

Bryan Thibodeau wrote:
> Hi -
>
> I have an application using a QTableWidget, and I
> would like to be able to respond to right-click events
> on cells in the table (but not with a context menu). 
> Ideally, I would like to get the QTableWidget to emit
> a signal with the row and column of the cell that was
> clicked on.  Any help would be much appreciated.
>
> Thanks.
> Bryan
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>   


---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.


Message 4 in thread

Hmm those seem going about the hard way.  Just set

setContextMenuPolicy(Qt::CustomContextMenu);

and then connect to
customContextMenuRequested(QPoint)

That is what I usually do when I want a right click menu on a 
qabstractitemview.  You can use the view.indexAt(point) to determine the 
index that is being right clicked on.

-Benjamin Meyer

On Tuesday 19 June 2007 15:47:12 Susan Macchia wrote:
> There are a couple possible techniques you can use that come to mind:
>
>    1. Use an event filter in the parent class that holds the
>       QTableWidget.  This could capture the mouse right click events and
>       the co-ordinates.  From there you can query the widget and find
>       out which cell is involved (using QTableView::rowAt &
>       QTableView::columntAt, for example)
>    2. Derive from QTableWidget, your own widget which emits the signal.
>       Your derivation must extend ::mousePressEvent to use the technique
>       in (1) to emit the signal with the cell.
>
> HTH,
> Susan
>
> Bryan Thibodeau wrote:
> > Hi -
> >
> > I have an application using a QTableWidget, and I
> > would like to be able to respond to right-click events
> > on cells in the table (but not with a context menu).
> > Ideally, I would like to get the QTableWidget to emit
> > a signal with the row and column of the cell that was
> > clicked on.  Any help would be much appreciated.
> >
> > Thanks.
> > Bryan
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body. List archive and information:
> > http://lists.trolltech.com/qt-interest/
>
> ---
>
> This communication contains confidential information. If you are not the
> intended recipient please return this email to the sender and delete it
> from your records.
>
> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der
> beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den
> Absender zurück und löschen Sie die E-mail aus Ihrem System.


--
 [ signature omitted ] 

Message 5 in thread

Benjamin Meyer schrieb:
> Hmm those seem going about the hard way.  Just set
> 
> setContextMenuPolicy(Qt::CustomContextMenu);
> 
> and then connect to
> customContextMenuRequested(QPoint)

That's a nice trick; I'll have to remember that :-)
However, I never thought of reimplementing a Qt class to apply my own 
tweaks as "the hard way"; thanks to the clean OO approach and the well 
thought-out class design it just came as natural as breathing :-)) A 
disadvantage is that it clutters your project with Q*Ext(ended) classes, 
but the advantage is that (IMHO) it's more transparent in terms of 
maintanance and documentation than any "casual" hack...

Just to give my 5 cents here for today. I don't inted to start a 
flamewar about The One Implementation Style here.

Martin

P. S. Just started getting into Java these days. Somehow I miss the Qt 
docs and the easy discoverability of the libraries...

-- 
 [ signature omitted ] 

Message 6 in thread

This is good for popping up menus, but if you want to do other things, 
you have to go with one of the 2 options I describe.


Benjamin Meyer wrote:
> Hmm those seem going about the hard way.  Just set
>
> setContextMenuPolicy(Qt::CustomContextMenu);
>
> and then connect to
> customContextMenuRequested(QPoint)
>
> That is what I usually do when I want a right click menu on a 
> qabstractitemview.  You can use the view.indexAt(point) to determine the 
> index that is being right clicked on.
>
> -Benjamin Meyer
>
> On Tuesday 19 June 2007 15:47:12 Susan Macchia wrote:
>   
>> There are a couple possible techniques you can use that come to mind:
>>
>>    1. Use an event filter in the parent class that holds the
>>       QTableWidget.  This could capture the mouse right click events and
>>       the co-ordinates.  From there you can query the widget and find
>>       out which cell is involved (using QTableView::rowAt &
>>       QTableView::columntAt, for example)
>>    2. Derive from QTableWidget, your own widget which emits the signal.
>>       Your derivation must extend ::mousePressEvent to use the technique
>>       in (1) to emit the signal with the cell.
>>
>> HTH,
>> Susan
>>
>> Bryan Thibodeau wrote:
>>     
>>> Hi -
>>>
>>> I have an application using a QTableWidget, and I
>>> would like to be able to respond to right-click events
>>> on cells in the table (but not with a context menu).
>>> Ideally, I would like to get the QTableWidget to emit
>>> a signal with the row and column of the cell that was
>>> clicked on.  Any help would be much appreciated.
>>>
>>> Thanks.
>>> Bryan
>>>
>>> --
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>> "unsubscribe" in the subject or the body. List archive and information:
>>> http://lists.trolltech.com/qt-interest/
>>>       
>> ---
>>
>> This communication contains confidential information. If you are not the
>> intended recipient please return this email to the sender and delete it
>> from your records.
>>
>> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der
>> beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den
>> Absender zurück und löschen Sie die E-mail aus Ihrem System.
>>     
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>   


---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.