Drag and Drop, QListWidget, and QApplication:mouseButtons()



  • Hello

    I have an application with a QListWidget, in the window of the application (MainWindow) a slot there is
    @
    void evLstWdgPressed(QModelIndex index);
    @

    I connect with:

    @
    connect(
    ui->listWidget,
    SIGNAL(pressed(QModelIndex)),
    this,
    SLOT(evLstWdgPressed(QModelIndex))
    );
    @

    and implemented as well:

    @
    void MainWindow::evLstWdgPressed(QModelIndex index)
    {
    if ( QApplication::mouseButtons() == Qt::NoButton )
    ui->text->appendPlainText("\tQt::NoButton");
    else if ( QApplication::mouseButtons() == Qt::LeftButton )
    ui->text->appendPlainText("\tQt::LeftButton");
    else if ( QApplication::mouseButtons() == Qt::MidButton )
    ui->text->appendPlainText("\tQt::MidButton");
    else if ( QApplication::mouseButtons() == Qt::MiddleButton )
    ui->text->appendPlainText("\tQt::MiddleButton");
    else if ( QApplication::mouseButtons() == Qt::XButton1 )
    ui->text->appendPlainText("\tQt::XButton1");
    else if ( QApplication::mouseButtons() == Qt::XButton2 )
    ui->text->appendPlainText("\tQt::XButton2");
    else if ( QApplication::mouseButtons() == Qt::RightButton )
    ui->text->appendPlainText("\tQt::RightButton");
    else
    ui->text->appendPlainText("\tNO DETECTED " + tr("%1").number(QApplication::mouseButtons()));

    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;
    
    QList <QUrl> urls;
    QUrl url("file:///E:/arch.zip");
    
    urls.append(url);
    mimeData->setUrls(urls);
    drag->setMimeData(mimeData);
    
    drag->exec&#40;Qt::CopyAction&#41;;
    

    }
    @

    The problem is that QApplication:mouseButtons () detects the button pressed the first time that runs the signal, the rest of the times do not detect it.

    I try to detect button to differentiate a drag and drop of a right click to display a shortcut menu.

    Any suggestions? What I am doing wrong?

    Thanks a lot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.