Adding right click menu on QTableWidget
-
Is it possible to right click a table widget and select one element, and doing some operation after it?
-
@suslucoder
Yes.You might start by reading e.g. https://forum.qt.io/topic/94905/simpliest-way-for-creating-contextmenu-for-qtablewidget-cells
-
@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)); }
-
Hi,
What exactly is your issue ?
Is your slot called ?
What do you expect ?
What do you get ? -
@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 chartvoid 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)); }
-
That's what is no clear.
Your timer is already running and you already called the slot in your constructor.
-
@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? -
@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
-
@nagesh said in Adding right click menu on QTableWidget:
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.