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. Adding right click menu on QTableWidget
Forum Update on Monday, May 27th 2025

Adding right click menu on QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5widgettable widget
9 Posts 4 Posters 5.1k 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.
  • D Offline
    D Offline
    deleted286
    wrote on 16 Mar 2021, 07:30 last edited by
    #1

    Is it possible to right click a table widget and select one element, and doing some operation after it?

    J 1 Reply Last reply 16 Mar 2021, 07:48
    0
    • D deleted286
      16 Mar 2021, 07:30

      Is it possible to right click a table widget and select one element, and doing some operation after it?

      J Online
      J Online
      JonB
      wrote on 16 Mar 2021, 07:48 last edited by JonB
      #2

      @suslucoder
      Yes.

      You might start by reading e.g. https://forum.qt.io/topic/94905/simpliest-way-for-creating-contextmenu-for-qtablewidget-cells

      D 1 Reply Last reply 16 Mar 2021, 11:13
      3
      • J JonB
        16 Mar 2021, 07:48

        @suslucoder
        Yes.

        You might start by reading e.g. https://forum.qt.io/topic/94905/simpliest-way-for-creating-contextmenu-for-qtablewidget-cells

        D Offline
        D Offline
        deleted286
        wrote on 16 Mar 2021, 11:13 last edited by
        #3

        @JonB Thank you. I did my right click menu.

        I want to draw a chart when i clicked this menu.
        I have these, im adding values into the series on my timer_slot.
        How can i do it, when i clicked my menu item, it should create a chart.

        ```
        
        ui->setupUi(this);
            tableWidget = new QTableWidget();
            timer = new QTimer();
        
           connect(timer, SIGNAL(timeout()), SLOT(Timer_Slot()));
            timer->start(500);
        
           grafik_olustur();
        
        void VeriGoster::grafik_olustur()
        {
            chart = new QChart();
            series = new QLineSeries();
            series->setName(srAd);
            series->setColor("green");
            chart->addSeries(series);
            chart->legend()->setVisible(true);
            chart->setAnimationOptions(QChart::AllAnimations);
        
        QValueAxis *axisX = new QValueAxis();
        axisX->setTickCount(5);
        axisX->setRange(0, +2);
        chart->addAxis(axisX, Qt::AlignBottom);
        series->attachAxis(axisX);
        
        QValueAxis *axisY = new QValueAxis;
        axisY->setTickCount(5);
        axisY->setRange(0,2);
        chart->addAxis(axisY, Qt::AlignLeft);
        series->attachAxis(axisY);
        
        chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
        ui->gridLayout->addWidget(chartView);
        

        }

        void VeriGoster::Timer_Slot()
        {
            static float q_x=0;
            if(!queue.isEmpty())
            {
               double num=queue.dequeue();
               q_x += 0.1;
               series->append(q_x, num);
               chart->update();
        
           qDebug() << q_x << num;
         }
        

        }

        void VeriGoster::on_tableWidget_customContextMenuRequested(const QPoint &pos)
        {
        QMenu *menu = new QMenu(this);
        QAction *ciz = new QAction("Grafik Çiz");
        connect(ciz, SIGNAL(triggered()), this, SLOT(grafik_olustur()));
        menu->addAction(ciz);
        menu->popup(ui->tableWidget->viewport()->mapToGlobal(pos));
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Mar 2021, 19:00 last edited by
          #4

          Hi,

          What exactly is your issue ?
          Is your slot called ?
          What do you expect ?
          What do you get ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply 17 Mar 2021, 06:04
          0
          • S SGaist
            16 Mar 2021, 19:00

            Hi,

            What exactly is your issue ?
            Is your slot called ?
            What do you expect ?
            What do you get ?

            D Offline
            D Offline
            deleted286
            wrote on 17 Mar 2021, 06:04 last edited by
            #5

            @SGaist My issue is, when i clicked the "draw", whick is a right click menu item on my table,
            i want to start adding datas to my chart.

            I have timer slot for adding datas in series, and i have the above code script which is my right click menu.
            My question is how can i connect them for when i clicked it goes to timer slot and start drawing chart

            void VeriGoster::on_tableWidget_customContextMenuRequested(const QPoint &pos)
            {
            QMenu *menu = new QMenu(this);
            QAction *ciz = new QAction("draw");
            menu->addAction(ciz);
            menu->popup(ui->tableWidget->viewport()->mapToGlobal(pos));
            }
            
            J 1 Reply Last reply 17 Mar 2021, 20:41
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 17 Mar 2021, 20:05 last edited by
              #6

              That's what is no clear.

              Your timer is already running and you already called the slot in your constructor.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • D deleted286
                17 Mar 2021, 06:04

                @SGaist My issue is, when i clicked the "draw", whick is a right click menu item on my table,
                i want to start adding datas to my chart.

                I have timer slot for adding datas in series, and i have the above code script which is my right click menu.
                My question is how can i connect them for when i clicked it goes to timer slot and start drawing chart

                void VeriGoster::on_tableWidget_customContextMenuRequested(const QPoint &pos)
                {
                QMenu *menu = new QMenu(this);
                QAction *ciz = new QAction("draw");
                menu->addAction(ciz);
                menu->popup(ui->tableWidget->viewport()->mapToGlobal(pos));
                }
                
                J Online
                J Online
                JonB
                wrote on 17 Mar 2021, 20:41 last edited by JonB
                #7

                @suslucoder
                Like @SGaist said, it's not clear what you mean as the timer is already running and doing the drawing.

                Purely at a guess, maybe you interested in starting and stopping the timer/drawing from the action? In which case you could call timer->stop/start() to stop/start the timer as desired?

                1 Reply Last reply
                0
                • nageshN Offline
                  nageshN Offline
                  nagesh
                  wrote on 18 Mar 2021, 00:50 last edited by
                  #8

                  @suslucoder not able to clearly understand the question?
                  Currently following code is called in the constructor.

                  timer->start(500);
                  grafik_olustur();
                  

                  if you want to create the chart only during right click, comment above lines from constructor.

                  grafik_olustur(); //create chart first
                  timer->start(500); //adds values to chart
                  
                  D 1 Reply Last reply 18 Mar 2021, 06:05
                  1
                  • nageshN nagesh
                    18 Mar 2021, 00:50

                    @suslucoder not able to clearly understand the question?
                    Currently following code is called in the constructor.

                    timer->start(500);
                    grafik_olustur();
                    

                    if you want to create the chart only during right click, comment above lines from constructor.

                    grafik_olustur(); //create chart first
                    timer->start(500); //adds values to chart
                    
                    D Offline
                    D Offline
                    deleted286
                    wrote on 18 Mar 2021, 06:05 last edited by
                    #9

                    @nagesh said in Adding right click menu on QTableWidget:

                    @suslucoder

                    if you want to create the chart only during right click, comment above lines from constructor.

                    grafik_olustur(); //create chart first
                    timer->start(500); //adds values to chart
                    

                    this was the answer im searching for. Sorry for, i couldnt explain my question clearly.

                    1 Reply Last reply
                    0

                    1/9

                    16 Mar 2021, 07:30

                    • Login

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