Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    3
    169
    Loading More Posts
    • 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.
    • ademmler
      ademmler last edited by 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

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @ademmler last edited by jsulm

        @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 Reply Quote 2
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          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 Reply Quote 1
          • First post
            Last post