QItemDelegate Context Menu
Dear All
We have a QTableWidget and we make a delegate for this. For one of the coloumn we need a context menu. We could bring a context menu but the problem is context menu is not standart. Is there a solution for this, or can you make a sugestion for this?
Please help
Re: QItemDelegate Context Menu
Delegate has nothing to do with context menus. You have to do that in the view like for any other widget.
Re: QItemDelegate Context Menu
What I mean is like this
In my delegate fuction I have createActions to create action which changes in every row.
Code:
void ProformaDelegate::createActions()
{
fiyat_tipleri.exec("SELECT id, stokid from table where if = '" + xxx +"';");
int i = 0;
while(fiyat_tipleri.next()){
recentFileActs
[i
] = new QAction(fiyat_tipleri.
value(3).
toString(),
this);
++i;
sayi = i;
}
}
And in createEditor part I ask for the delegate.
Code:
else if(index.column() == 5 || index.column() == 8)
{
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
editor->setMinimum(0);
editor->setMaximum(4000000000);
editor->setDecimals(4);
editor->setSuffix(" " + totalParaBirimi);
editor->setAlignment(Qt::AlignRight);
for (int i = 0; i < sayi; ++i)
editor->addAction(recentFileActs[i]);
editor->setContextMenuPolicy(Qt::ActionsContextMenu);
return editor;
}
The problem is I could not start createActions() functions from createEditor() part, and also send information (xxx) for the SQL query
Re: QItemDelegate Context Menu
What do you mean you couldn't start it? It doesn't compile or you don't see the result or...? BTW. I think your SQL statement is invalid - 'if' is probably a function name which may cause a clash with a database field with the same name if you have one.
Re: QItemDelegate Context Menu
I dont have a problem in compiling.
But what I want to do is everytime I come to column 5 of column 8 I want the delegate start fuction createActions(), but when I write like this
Code:
if(index.column() == 5 || index.column() == 8)
{
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
editor->setMinimum(0);
editor->setMaximum(4000000000);
editor->setDecimals(4);
editor->setSuffix(" " + totalParaBirimi);
editor->setAlignment(Qt::AlignRight);
createActions();
for (int i = 0; i < sayi; ++i)
editor->addAction(recentFileActs[i]);
editor->setContextMenuPolicy(Qt::ActionsContextMenu);
return editor;
}
I could not compile it. I get a error like
error: passing `const ProformaDelegate'
as `this' argument of `void ProformaDelegate::createActions()' discards qualifie
rs
Re: QItemDelegate Context Menu
any idea? How can I do it?
Re: QItemDelegate Context Menu
In general you shouldn't do it this way or you should make your createActions() method const.
Re: QItemDelegate Context Menu
I understand,
But can you help me how can I do it?
What I would like to do is,
Think about a qtablewidget,
for every row there are different data. For everydata (for every row) I would like to biring a information from SQL, when context menu requested, I need to run sql query with a data on the row and bring information for the row with context.
Can you help?
Re: QItemDelegate Context Menu
Reimplement contextMenuEvent() from QTableWidget.
Re: QItemDelegate Context Menu
any example you could help me?
Re: QItemDelegate Context Menu
Quote:
Originally Posted by
aekilic
any example you could help me?
http://www.qtcentre.org/forum/p-drag...ostcount2.html
Re: QItemDelegate Context Menu
the problem I have now is,
I could use
connect(tableProformaindex, SIGNAL(customContextMenuRequested (QPoint)), this, SLOT(createActions(QPoint)));
but after the window open it works one time, but after that it never works.
Re: QItemDelegate Context Menu
any thing you could help me?
Re: QItemDelegate Context Menu
Quote:
Originally Posted by
aekilic
the problem I have now is,
I could use
connect(tableProformaindex, SIGNAL(customContextMenuRequested (QPoint)), this, SLOT(createActions(QPoint)));
but after the window open it works one time, but after that it never works.
There is no way we can help you unless you show the relevant code.
Re: QItemDelegate Context Menu
Dear Jpn
What we are trying to is, for every row of a QTableWidget, we need a new menu...
Is there a way that we could do it?
Re: QItemDelegate Context Menu
Yes, create a regular context menu :) In the event handler create an instance of QMenu, assign it the actions you want to show and call QMenu::exec(). And please read the docs.
Re: QItemDelegate Context Menu
Quote:
Originally Posted by
aekilic
What we are trying to is, for every row of a QTableWidget, we need a new menu...
Is there a way that we could do it?
I have already posted a link which shows an example how to do it. Use QTableWidget::itemAt() to get the item below requested point. Here's one more example with signals and slots: http://www.qtcentre.org/forum/p-qlis...ostcount5.html