Results 1 to 2 of 2

Thread: unable to generate action in popup menu

  1. #1
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question unable to generate action in popup menu

    how to create a popup menu on right mouse click button?i saw the answer in ur website.when i am trying to implement ur example in my code,i'm able to generate the popup menu but unable to implement the action and here is ur code:
    void MainWindow::mousePressEvent(QMouseEvent *event)
    {
    if(event->Button()==Qt::RightButton)
    {
    this->Popup(event->pos());
    event->Accept();
    }
    }
    void MainWindow::Popup(const QPoint &pt)
    {
    QPoint global = this->mapToGlobal(pt);
    QMenu *pPopup = new QMenu(this);
    QAction *pAction1 = new QAction("House",this);
    QAction *pAction2 = new QAction("Hut",this);
    pPopup->addAction(pAction1);
    pPopup->addAction(pAction2);
    QAction *pItem = pPopup->exec(global);
    if(pItem==pAction1)
    {
    QLabel *label = new QLabel(this);
    label->setPixmap(QPixmap(":/House.png");
    label->setGeometry(0,0,20,20);
    qDebug("hi...");
    }
    else if(pItem==pAction2)
    {
    QLabel *label1 = new QLabel(this);
    label1->setPixmap(QPixmap(":/Hut.png");
    label1->setGeometry(10,10,20,20);
    qDebug("Hello...");
    }
    }
    I'm unable to place that png image in my application whenever i'm trying to click my right mouse Button,but able to see the qDebug statement for both the conditions in compile output window or application output window.Reply as early as possible

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unable to generate action in popup menu

    you create a new label, but you don't show it (at least not in the code you posted here).

Similar Threads

  1. Replies: 2
    Last Post: 25th November 2009, 06:15
  2. Popup Menu
    By kavinsiva in forum Newbie
    Replies: 2
    Last Post: 25th September 2009, 10:09
  3. Replies: 3
    Last Post: 17th May 2009, 20:17
  4. unable to popup the QSlider on top of the pushButton
    By qwakaw in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 10:30
  5. Action-Menu-Button
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 1st October 2007, 16:41

Tags for this Thread

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.