Results 1 to 2 of 2

Thread: How to pass the item value from rightClick popud menu to TextEdit

  1. #1
    Join Date
    Mar 2009
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Exclamation How to pass the item value from rightClick popud menu to TextEdit

    How to get the value from item treeWidget after i right click on the item and choose "Registration" option from popud menu
    then item value will show up in TextEdit.

    Please Someone see and modify my code


    /MyProgram.cpp
    ///////////////////////////////////////////////////////////////

    menu = new QMenu( this );
    Register = new QAction(tr("Registration"), this);
    connect(Register, SIGNAL(triggered()), qApp, SLOT(RegisterMenu()));
    menu->addAction( Register);

    ui.treeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
    connect( ui.treeWidget, SIGNAL( customContextMenuRequested( const QPoint & )),
    this, SLOT( customContentsMenu( const QPoint & )));


    void MyProgram::customContentsMenu( const QPoint &pos )
    {

    QTreeWidgetItem *item = ui.treeWidget->itemAt(pos);
    if (!item)
    return;

    menu->exec(ui.treeWidget->viewport()->mapToGlobal(pos));
    }


    void MyProgram::RegisterMenu()
    {
    //the textedit should show up the item value here which i select from right click item on TreeWidget, but i don't know how to get the value

    }

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to pass the item value from rightClick popud menu to TextEdit

    You can select the item on to which the user has right-clicked and then change the text. Here's the code

    Qt Code:
    1. void MyProgram::customContentsMenu( const QPoint &pos )
    2. {
    3. QTreeWidgetItem *item = ui.treeWidget->itemAt(pos);
    4. if (!item)
    5. return;
    6. ui.treeWidget->setCurrentItem(item);
    7.  
    8. menu->exec(ui.treeWidget->viewport()->mapToGlobal(pos));
    9. }
    10.  
    11. void MyProgram::RegisterMenu()
    12. {
    13. QTreeWidgetItem *item = ui.treeWidget->currentItem();
    14. if(item)
    15. item->setText("Text that you want");
    16. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. creating a "path" for the menu item
    By roxton in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2009, 16:32
  2. Menu Item has no highlight
    By blackfox in forum Qt Programming
    Replies: 6
    Last Post: 24th September 2008, 12:17

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.