migel
1st June 2011, 13:43
so I made connection to create a popup menu
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(provideContexMenu(const QPoint&)));
and the slot to print the menu:
void ListView::provideContexMenu(const QPoint &position) {
QMenu menu(this);
QAction* open = new QAction("Open", this);
connect(open, SIGNAL(triggered()), this, SLOT(open()));
menu.addAction(open);
menu.exec(QCursor::pos());
}
void ListView::open() {
// action here depends on info
}
how to actually have the information from the cell or the row ??? if the provideContextMenu passing just the const QPoint &position ?
Please advise, super thank you :)
Added after 1 32 minutes:
I am trying to get the item using itemAt but the app crashes when I right click on different column then I want to.
when I click on column 1 working fine, anything else the app crashes.
void ListView::provideContexMenu(const QPoint &position) {
selectedItem = this->itemAt(position.x(), position.y());
if (selectedItem->column() == 1) {
menu->addAction(shareAct);
menu->addAction(openAct);
menu->addAction(viewAct);
menu->exec(QCursor::pos());
}
}
what I do wrong here ? is there another way to handle right click on specific column and receive the item info ??
thanks for help
It actually crashes on column 0 but on column 1 and 2 still prints the menu
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(provideContexMenu(const QPoint&)));
and the slot to print the menu:
void ListView::provideContexMenu(const QPoint &position) {
QMenu menu(this);
QAction* open = new QAction("Open", this);
connect(open, SIGNAL(triggered()), this, SLOT(open()));
menu.addAction(open);
menu.exec(QCursor::pos());
}
void ListView::open() {
// action here depends on info
}
how to actually have the information from the cell or the row ??? if the provideContextMenu passing just the const QPoint &position ?
Please advise, super thank you :)
Added after 1 32 minutes:
I am trying to get the item using itemAt but the app crashes when I right click on different column then I want to.
when I click on column 1 working fine, anything else the app crashes.
void ListView::provideContexMenu(const QPoint &position) {
selectedItem = this->itemAt(position.x(), position.y());
if (selectedItem->column() == 1) {
menu->addAction(shareAct);
menu->addAction(openAct);
menu->addAction(viewAct);
menu->exec(QCursor::pos());
}
}
what I do wrong here ? is there another way to handle right click on specific column and receive the item info ??
thanks for help
It actually crashes on column 0 but on column 1 and 2 still prints the menu