how to judge which button click the QTreeWidgetItem?

322 views
Skip to first unread message

lvbing lvbing

unread,
Nov 4, 2010, 5:08:16 AM11/4/10
to qt-in...@trolltech.com, qt-c...@googlegroups.com
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

lvbing lvbing

unread,
Nov 4, 2010, 8:01:17 PM11/4/10
to qt-in...@trolltech.com, qt-c...@googlegroups.com


---------- Forwarded message ----------
From: lvbing lvbing <lvbin...@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 <xzeke...@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 <xzeke...@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?

_______________________________________________
Qt-interest mailing list
Qt-in...@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




Goldfish Huang

unread,
Nov 5, 2010, 2:50:26 AM11/5/10
to qt-c...@googlegroups.com
try this:


void MainWindow::on_MyTree_itemClicked ( QTreeWidgetItem * item, int column )
{

if(qApp->mouseButtons()!=Qt::LeftButton) return;

qDebug() << "on_MyTree_itemClicked"
<< item->text(column);
//to do somthing
}

> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“Qt中文”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 qt-c...@googlegroups.com
> 要取消订阅此网上论坛,请发送电子邮件至 qt-china+u...@googlegroups.com
> 若有更多问题,请通过 http://groups.google.com/group/qt-china?hl=zh-CN 访问此网上论坛。
>

Reply all
Reply to author
Forward
0 new messages