Hi everyone,
I have a QTabelView with a few rows and I would like to make a Popup menu that when I selectm for example the first item in the menu, that shows me the value of the first cell in the current row.
Hi everyone,
I have a QTabelView with a few rows and I would like to make a Popup menu that when I selectm for example the first item in the menu, that shows me the value of the first cell in the current row.
I understand the words. I don't understand why do you expect others to guess what you are having problems with. So far you told us what you were working on, not more. So I replied that I was very happy for you that you had something to fill your time with.
On the other hand if you want to ask for something, spare 30 minutes and read through the text behind the link I gave you (pay special attention to the "Be precise and informative about your problem" and "Questions Not To Ask" parts) and then restate your problem.
Yes you are right.
So, I've recasted my problem.
How to make a Popup menu which is connected to TableView and when I press one item on menu displays the value of the first cell in selected row?
So, I've two problems:
1. How to create a Popup menu connected to TableView?
2. How do display the value o some cell in selected row.
Forgive me, I did't want to do anyone a clairvoyant.
There are basically three ways to do that. Take a look at QWidget::contextMenuPolicy property to see description of all of them.
Use QModelIndex::data() to retrieve the value of an index of a table.2. How do display the value o some cell in selected row.
Thanks,
I've made:
but, unfortunately, when I'm pressing a right mouse button any menu does not appear :/Qt Code:
TableResult->setRowCount(3); TableResult->setColumnCount(5); TableResult->setContextMenuPolicy(Qt::ActionsContextMenu); newAct->setStatusTip(tr("Create a new file")); connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); menu.addAction(newAct);To copy to clipboard, switch view to plain text mode
It doesn't work that way. You have to add the action to the widget, not to some temporary menu object.
TomASS (27th September 2009)
Ok, now I've:
Qt Code:
newAct->setStatusTip(tr("Create a new file")); TableResult->addAction(newAct); TableResult->setContextMenuPolicy(Qt::ActionsContextMenu); connect(newAct, SIGNAL(triggered()),TableResult,SLOT(newFile()));To copy to clipboard, switch view to plain text mode
and
Qt Code:
void MainWindow::newFile(){ }To copy to clipboard, switch view to plain text mode
of course I've in header file:
Qt Code:
{ Q_OBJECT public: ~MainWindow(); QAction *newAct; QTableWidget *TableResult; private slots: void newFile(); private: int t; };To copy to clipboard, switch view to plain text mode
but, menu appears, but when I click on "new file" nothing happens :/ Method MainWindow::newFile will not start
Last edited by TomASS; 27th September 2009 at 20:59.
You connect the signal to a slot in the table, not in the main window.Qt Code:
connect(newAct, SIGNAL(triggered()),TableResult,SLOT(newFile()));To copy to clipboard, switch view to plain text mode
Thank you for your quick response and for your patience, but how can I connect the signal to TableView?
And second question, how can I read a value of selected (by showing menu) row, you've wrote by "QModelIndex::data()" but in newFile() funcition I haven't data :/
Are you asking me about the prototype of QObject::connect() or something else?
If you have the selected row, you have its index. When you have its index, you can call data() on it.... but in newFile() funcition I haven't data :/
TomASS (28th September 2009)
You have declared the slot in your MainWindow Class, but connected the Signal to your TreeWidget. So, to connect to your newFile() Slot, your connect would have to look like this:
Take a look at the link wysota posted if you want to know more about this.Qt Code:
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));To copy to clipboard, switch view to plain text mode
As you're using a TableWidget, not a TableView, simply call
Or, if you need data from another column in the rowQt Code:
TableResult->currentItem()->data(...)To copy to clipboard, switch view to plain text mode
If you want to use a TableView, you'll have to work with indexes, of course, but that's pretty much the same.Qt Code:
TableResult->item(TableResult->currentRow(), your Column)->data(...)To copy to clipboard, switch view to plain text mode
TomASS (28th September 2009)
Thanks a lot!
I's working!
Last edited by TomASS; 28th September 2009 at 09:25.
Bookmarks