PDA

View Full Version : Getting widget from Qpoint



codeman
22nd June 2010, 15:23
Hello Friends,

how can I get the widget from a point when I make a custom context.


I have a groupox with many lineedits and when I link all edits to the same action I have to differentiate.
this does not the trick. I think I get the points in relation to the lineedit and not to the Qmainwindow or???




void Project::setSaveForAllProjectsTriggered()

{
QString test=this->childAt(this->m_contextTriggerPoint)->objectName();

}




this is my contextmenu function




void Project::showContextMenu(const QPoint &position)

{

QList<QAction *> actions;

this->m_contextTriggerPoint=position;
actions.append(actSaveForAllProjects);

if (actions.count() > 0)
QMenu::exec(actions, this->mylineedit->mapToGlobal(position));
}

high_flyer
22nd June 2010, 15:39
a cleaner way would be to handle the context menu in the widget in which it was clicked.
But if you must handle it on a parent, just have the widget which was right clicked to send a signal to the parent, therein the slot you can ask sender() who the sender is.
You don't need to mess with the position at all.