Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drag and Drop, QListWidget, and QApplication:mouseButtons()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChanchoCiego
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved