Results 1 to 2 of 2

Thread: Getting widget from Qpoint

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Getting widget from Qpoint

    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???

    Qt Code:
    1. void Project::setSaveForAllProjectsTriggered()
    2.  
    3. {
    4. QString test=this->childAt(this->m_contextTriggerPoint)->objectName();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 



    this is my contextmenu function

    Qt Code:
    1. void Project::showContextMenu(const QPoint &position)
    2.  
    3. {
    4.  
    5. QList<QAction *> actions;
    6.  
    7. this->m_contextTriggerPoint=position;
    8. actions.append(actSaveForAllProjects);
    9.  
    10. if (actions.count() > 0)
    11. QMenu::exec(actions, this->mylineedit->mapToGlobal(position));
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Getting widget from Qpoint

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. ChildAt(Qpoint) - related
    By jsmith in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2009, 08:45
  2. Replies: 10
    Last Post: 17th September 2009, 20:12
  3. QtScript QPoint
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2009, 09:33
  4. QPoint Limitation
    By archanasubodh in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 10:22
  5. Confusion with QPoint
    By therealjag in forum Qt Programming
    Replies: 9
    Last Post: 14th February 2006, 17:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.