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. ListWidget "How to check Mouse Event" when item has been clicked?

ListWidget "How to check Mouse Event" when item has been clicked?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 959 Views
  • 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by ademmler
    #1

    Hi folks,

    After an listwodget item has been clicked I want to check the mouse button, and react on the left/right button differently.
    I have this code in my app. But since I added "QMouseEvent *e" to the function nothing happens any longer ...

    void MyApp::on_listWidget_itemClicked(QMouseEvent *e)
    {
       if (e->button() == Qt::LeftButton){
            int no = ui->listWidget->currentRow();
            QString cn = ui->listWidget->currentItem()->text();
            if( ui->listWidget->currentItem()->isSelected() ) {
                sendMessage("Item deactivated: " + cn + " Index :" + QString::number(no), msg_debug);
            } else {
                sendMessage("Item activated: " + cn + " Index :" + QString::number(no), msg_debug);
            }
        }
    }
    

    Regards Alex

    jsulmJ 1 Reply Last reply
    0
    • ademmlerA ademmler

      Hi folks,

      After an listwodget item has been clicked I want to check the mouse button, and react on the left/right button differently.
      I have this code in my app. But since I added "QMouseEvent *e" to the function nothing happens any longer ...

      void MyApp::on_listWidget_itemClicked(QMouseEvent *e)
      {
         if (e->button() == Qt::LeftButton){
              int no = ui->listWidget->currentRow();
              QString cn = ui->listWidget->currentItem()->text();
              if( ui->listWidget->currentItem()->isSelected() ) {
                  sendMessage("Item deactivated: " + cn + " Index :" + QString::number(no), msg_debug);
              } else {
                  sendMessage("Item activated: " + cn + " Index :" + QString::number(no), msg_debug);
              }
          }
      }
      

      Regards Alex

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @ademmler said in ListWidget "How to check Mouse Event" when item has been clicked?:

      QMouseEvent

      For that you have to override https://doc.qt.io/qt-5/qwidget.html#mousePressEvent
      See here how to do that: https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Just so its clear.

        You cannot go around and add/change parameters to Widgets build in signals.

        ItemClicked() signal is
        on_listWidget_itemClicked(QListWidgetItem *item)

        and if you change the parameter (item) then your slot will no longer be called.

        1 Reply Last reply
        1

        • Login

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