Results 1 to 3 of 3

Thread: QlistWidget,context menu and passing currentitem() to another form

  1. #1
    Join Date
    Mar 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default QlistWidget,context menu and passing currentitem() to another form

    Hi.

    What I'm trying to do is load list of accounts from database to QlistWidget,then when I right click on account, a context menu pops out.
    After I choose "Manage User", I want to get text from selected row and pass it to the open form.
    Everything works well,the only problem is,that i have no idea how to get text form row using pos

    A little bit of code:

    Qt Code:
    1. QString RMClass::ShowCXmenu(const QPoint& pos){
    2.  
    3. /////////////////////////////////////////////////////////////////////////////////////////////
    4. openUsrMgr_WND = new QAction(tr("Manage User"),this);
    5. openUsrMgr_WND->setShortcut(QKeySequence::Open);
    6. // openUsrMgr_WND->setStatusTip(tr(""));
    7. connect(openUsrMgr_WND, SIGNAL(triggered()),this, SLOT(USRMGR()));
    8.  
    9. /////////////////////////////////////////////////////////////////////////////////////////////
    10. //USRDELETE = new QAction(tr("Delete User"), this);
    11. //usrmgg->setShortcut(QKeySequence::New);
    12. // USRDELETE->setStatusTip(tr(""));
    13. // connect(USRDELETE, SIGNAL(triggered()),this, SLOT(USRDEL()));
    14.  
    15. //////////////////////////////////////////////////////////////////////////////////////////////
    16.  
    17. QMenu myMenu;
    18. myMenu.addAction(openUsrMgr_WND);
    19. myMenu.addSeparator();
    20.  
    21. // myMenu.addAction(USRDELETE);
    22. myMenu.exec(QCursor::pos());
    23.  
    24.  
    25.  
    26.  
    27.  
    28. return UserNameCX; //that should return text from selected row
    29.  
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 

    I also tried:
    Qt Code:
    1. UserNameCX = ui->listWidget->currentItem()->text();
    To copy to clipboard, switch view to plain text mode 

    But everytime i right click inside listWidget program crashing


    Thanks in advance
    xer

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QlistWidget,context menu and passing currentitem() to another form

    QListView::indexAt() or QListWidget::itemAt() will identify which index/item is under that point (if any)

  3. #3
    Join Date
    Mar 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QlistWidget,context menu and passing currentitem() to another form

    Hi..
    It works...
    Thank You Chris...

Similar Threads

  1. Replies: 1
    Last Post: 4th November 2011, 12:25
  2. Passing an object from one form to the other.
    By cbarmpar in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2008, 15:12
  3. QListWidget context menu using Designer
    By palsa in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2008, 14:57
  4. QListWidget::currentItem() issue
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 16th April 2007, 12:04
  5. Replies: 9
    Last Post: 17th April 2006, 21:32

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.