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. How to detect two click events
Forum Updated to NodeBB v4.3 + New Features

How to detect two click events

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 1.6k 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.
  • R Offline
    R Offline
    russjohn834
    wrote on last edited by
    #1

    Hi all,

    I have a QTableWidget. I need to return something when the cellClicked and a pushbutton clicked. Something like this:

    void MainWindow::on_tableWidget_cellClicked(int row, int column)
    {
       
       if(ui->pushButton_4->clicked()) -------> I cant do this!
       {
        qDebug()<< "\n content is:"<<ui->tableWidget->item(row,column=0)->text();
       }
    }
    

    It says:

    mainwindow.cpp:157:7: error: value of type 'void' is not contextually convertible to 'bool'
    

    What is the right way to do this?

    Thanks in advance

    jsulmJ JonBJ 2 Replies Last reply
    0
    • R russjohn834

      Hi all,

      I have a QTableWidget. I need to return something when the cellClicked and a pushbutton clicked. Something like this:

      void MainWindow::on_tableWidget_cellClicked(int row, int column)
      {
         
         if(ui->pushButton_4->clicked()) -------> I cant do this!
         {
          qDebug()<< "\n content is:"<<ui->tableWidget->item(row,column=0)->text();
         }
      }
      

      It says:

      mainwindow.cpp:157:7: error: value of type 'void' is not contextually convertible to 'bool'
      

      What is the right way to do this?

      Thanks in advance

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

      @russjohn834 You can't click at two different widgets at the same time. What do you really want to do?

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

      R 1 Reply Last reply
      4
      • R russjohn834

        Hi all,

        I have a QTableWidget. I need to return something when the cellClicked and a pushbutton clicked. Something like this:

        void MainWindow::on_tableWidget_cellClicked(int row, int column)
        {
           
           if(ui->pushButton_4->clicked()) -------> I cant do this!
           {
            qDebug()<< "\n content is:"<<ui->tableWidget->item(row,column=0)->text();
           }
        }
        

        It says:

        mainwindow.cpp:157:7: error: value of type 'void' is not contextually convertible to 'bool'
        

        What is the right way to do this?

        Thanks in advance

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @russjohn834
        As @jsulm says above. Unless maybe you have two mice (mouses?) & two hands ;-)

        What is this pushbutton? Is it a pushbutton you have put in the cell in the table widget? Is it a totally unrelated button somewhere else?

        If by any chance you mean it's unrelated/elsewhere, and you want to know if it was clicked previously to the cell click, you would have to store the fact that something else happened earlier into a variable to examine now. But I don't know if that's what you might mean!

        1 Reply Last reply
        1
        • jsulmJ jsulm

          @russjohn834 You can't click at two different widgets at the same time. What do you really want to do?

          R Offline
          R Offline
          russjohn834
          wrote on last edited by
          #4

          @jsulm
          I need to select a row in a QTabelWidget and press a button to send a signal (a string with cell content) and to open a new window.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            russjohn834
            wrote on last edited by
            #5

            @JonB
            As shown below. I selected the row. Now if I press Open button should open a new window with title as first column content (for ex here "PID02").
            table.JPG

            JonBJ 1 Reply Last reply
            0
            • R russjohn834

              @JonB
              As shown below. I selected the row. Now if I press Open button should open a new window with title as first column content (for ex here "PID02").
              table.JPG

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @russjohn834
              Ah. So you don't want to be writing any code in anything like on_tableWidget_cellClicked(int row, int column), that would be to do with clicking in the cell. You just want a slot for (each of) your pushbuttons' .clicked signal. In that you can look at what row(s) is/are selected in the table widget (you can make it only able to select a single row, not multiple rows nor individual cells, if you haven't already). Have a read through e.g. https://stackoverflow.com/questions/5927499/how-to-get-selected-rows-in-qtableview, something like

              QModelIndexList selection = yourTableView->selectionModel()->selectedRows();
              

              So here you do not bother to place a slot on the click to make the selection in the table widget, you let it handle that and you just use its selectedRows() after the event to see which items are currently selected.

              1 Reply Last reply
              5
              • R Offline
                R Offline
                russjohn834
                wrote on last edited by
                #7

                @JonB Thank you.

                I did this:

                void MainWindow::on_pushButton_4_clicked()
                {
                
                    QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                    qDebug()<<"\n The content is"<<selection; -------> How to get content
                
                }
                

                I'm getting output as:

                The content is (QModelIndex(1,0,0x0,QTableModel(0x37e460)))

                How do I extract the content of that particular cell?

                qwasder85Q Pablo J. RoginaP 2 Replies Last reply
                0
                • R russjohn834

                  @JonB Thank you.

                  I did this:

                  void MainWindow::on_pushButton_4_clicked()
                  {
                  
                      QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                      qDebug()<<"\n The content is"<<selection; -------> How to get content
                  
                  }
                  

                  I'm getting output as:

                  The content is (QModelIndex(1,0,0x0,QTableModel(0x37e460)))

                  How do I extract the content of that particular cell?

                  qwasder85Q Offline
                  qwasder85Q Offline
                  qwasder85
                  wrote on last edited by qwasder85
                  #8

                  @russjohn834 Use selectedIndexes() instead of selectedRows(). Then you can use each index' data()-function to see the data in the selected cell.

                  edit: I just realized you used selectedRows(0). In that case you can just do selection(0).data().toString() to get a QString representation of the index data.

                  1 Reply Last reply
                  3
                  • R Offline
                    R Offline
                    russjohn834
                    wrote on last edited by russjohn834
                    #9

                    @qwasder85 Thank you.

                    Dont know what I'm doing wrong here:

                     QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                        qDebug()<<"\n The content is"<<selection(0).data().toString();
                    

                    I'm getting error saying:

                    mainwindow.cpp:151:36: error: type 'QModelIndexList' (aka 'QList<QModelIndex>') does not provide a call operator
                    

                    Any idea?

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      russjohn834
                      wrote on last edited by
                      #10

                      I got it, was a typo. It should be:

                      selection[0].data().toString();
                      
                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        russjohn834
                        wrote on last edited by
                        #11

                        Thank you @jsulm , @JonB , @qwasder85 :)

                        1 Reply Last reply
                        1
                        • R russjohn834

                          @JonB Thank you.

                          I did this:

                          void MainWindow::on_pushButton_4_clicked()
                          {
                          
                              QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                              qDebug()<<"\n The content is"<<selection; -------> How to get content
                          
                          }
                          

                          I'm getting output as:

                          The content is (QModelIndex(1,0,0x0,QTableModel(0x37e460)))

                          How do I extract the content of that particular cell?

                          Pablo J. RoginaP Offline
                          Pablo J. RoginaP Offline
                          Pablo J. Rogina
                          wrote on last edited by
                          #12

                          @russjohn834 said in How to detect two click events:

                          void MainWindow::on_pushButton_4_clicked()

                          As a side note, try using more meaningful names for widgets...
                          Six months from now I bet you'll forget what button 4 is (is it Open? New? Edit?) so:

                          void MainWindow::on_pushButton_Open_clicked()
                          

                          seems pretty straightforward, right?

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          3
                          • R Offline
                            R Offline
                            russjohn834
                            wrote on last edited by
                            #13

                            @Pablo-J-Rogina That's very true. many thanks for your feedback :)

                            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