qApp-> mouseButtons()始终返回0

时间:2014-11-11 18:05:41

标签: c++ qt

我有Xubuntu 14.04 LTS,似乎qApp-> mouseButtons()总是返回0.

以下是一些代码:

班级定义:

class Interface : public QObject
{
    Q_OBJECT

    private:
    // ...
    QListWidget searchList;
    // ...

    public slots:
    // ...
    void moveCard(QListWidgetItem*);
    void clickCard(QListWidgetItem*);
    // ...
};

Consructor:

Interface::Interface() : QObject()
{  
    // ...
    QObject::connect(&searchList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(clickCard(QListWidgetItem*)));
    QObject::connect(&searchList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(moveCard(QListWidgetItem*)));
    // ...
}

老虎机:

void Interface::moveCard(QListWidgetItem* Item)
{
    auto buttons = qApp->mouseButtons();
    std::cout << buttons << std::endl;

    if(buttons & Qt::LeftButton)
        std::cout << "ha" << std::endl;
    else if(buttons & Qt::RightButton)
        std::cout << "ho" << std::endl;
}

void Interface::clickCard(QListWidgetItem* Item)
{
    auto buttons = qApp->mouseButtons();
    std::cout << buttons << std::endl;

    if(buttons & Qt::LeftButton)
        std::cout << "ha" << std::endl;
    else if(buttons & Qt::RightButton)
        std::cout << "ho" << std::endl;
}

因此,当我点击并双击项目时,我总是在终端获得0,但从不“ha”或“ho”。有谁知道如何解决这个问题?

0 个答案:

没有答案