[Qt-interest] Fwd: how to judge which button click the QTreeWidgetItem?

lvbing lvbing lvbing1981 at gmail.com
Mon Nov 8 01:38:07 CET 2010


Thanks to all:)

In Qt4,both the left and right button will emit the itemClicked signal after
clicked. and the signal itemClicked is emited after the mouseReleaseEvent.

so I do it:
class MTreeWdiget : public QTreeWidget
{
publict:
    ....
    void mouseReleaseEvent(QMouseEvent* event);
}

in the function mouseReleaseEvent,I can judget if the left or right button
clicked,so my problem was be resolved.

thanks for all.

PS:
1 qApp->buttons() will return 0 when emit the itemClicked.

On Fri, Nov 5, 2010 at 8:11 PM, John McClurkin <jwm at nei.nih.gov> wrote:

> lvbing lvbing wrote:
> >
> >
> > ---------- Forwarded message ----------
> > From: *lvbing lvbing* <lvbing1981 at gmail.com <mailto:lvbing1981 at gmail.com
> >>
> > Date: Thu, Nov 4, 2010 at 7:01 PM
> > Subject: Re: [Qt-interest] how to judge which button click the
> > QTreeWidgetItem?
> > To: Keith Rusler <xzekecomax at gmail.com <mailto:xzekecomax at gmail.com>>
> >
> >
> > I know,
> > but  when I click the right button,it will emit the signal:
> > itemClick(QTreeWidgetItem*,int).
> >
> > so I don't know who emit the signal itemClick,left button or right
> > button.and the result is:when I clicked
> > the left button,the itemClick will be done
> > and when I clicked the right button,the itemClick also will be done,but
> > I don't want to call the itemClick when
> > I clicked the right button!
> >
> > so how can I distinguish which button has been clicked when the signal
> > itemClicked be emited?
> >
> > thank all
> >
> >
> > On Thu, Nov 4, 2010 at 5:46 PM, Keith Rusler <xzekecomax at gmail.com
> > <mailto:xzekecomax at gmail.com>> wrote:
> >
> >     I think it should be quite normal if you really think about it.
> >     Because if you right click on any item, it should show a context
> >     menu for that item it was clicked on right?
> >
> >     On 4 November 2010 04:08, lvbing lvbing <lvbing1981 at gmail.com
> >     <mailto:lvbing1981 at gmail.com>> wrote:
> >
> >         hello all
> >             I have a QTreeWidget in my QMainWidows,and I have two
> >         functions,the one is left button click
> >         and the another is the right button to popup some Menu.
> >
> >         The code like this:
> >
> >         MainWindow::MainWindow() : QMainWindow()
> >         {
> >             setCentralWidget(view);
> >             view = new QTreeWidget(this);
> >             connect(view,SIGNAL(itemClicked ( QTreeWidgetItem *, int
> >         )),this,SLOT(on_MyTree_itemClicked( QTreeWidgetItem *, int )));
> >             init();
> >         }
> >
> >         void MainWindow::on_MyTree_itemClicked ( QTreeWidgetItem * item,
> >         int column )
> >         {
> >             qDebug() << "on_MyTree_itemClicked"
> >                 << item->text(column);
> >             //to do somthing
> >         }
> >
> >
> >         void MainWindow::contextMenuEvent(QContextMenuEvent * event)
> >         {
> >             qDebug() << "contextMenuEvent"
> >                 << event->pos().x()
> >                 << " and "
> >                 << event->pos().y();
> >             //To popup the menu when I click the right mouse button!
> >         }
> >
> >         But now I find when I clicked the right button,it will call
> >         the on_MyTree_itemClicked  slot first!!
> >         and how can I distinguish the left or right button?
> >
> >         thanks all
> >
> >         _______________________________________________
> >         Qt-interest mailing list
> >         Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> >         http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
> >
> >
>
> You might try installing an eventFilter on the QTreeWidget.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101108/6039ed7c/attachment.html 


More information about the Qt-interest-old mailing list