+ Reply to Thread
Results 1 to 16 of 16

Thread: Q3PopupMenu

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Q3PopupMenu

    Hello everybody,

    QT:4.1.1

    I am trying to popup a menu inside my QTableView. I get a error on compiling this code:
    Qt Code:
    1. void MainWindow::contextMenuEvent( QContextMenuEvent * )
    2. {
    3. Q3PopupMenu* contextMenu = new Q3PopupMenu( this );
    4. Q_CHECK_PTR( contextMenu );
    5. QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
    6. "ListView options</b></u></font>", this );
    7. caption->setAlignment( Qt::AlignCenter );
    8. contextMenu->insertItem( caption );
    9. contextMenu->insertItem( "&einfügen", this, SLOT(selectTable()) );
    10. contextMenu->exec( QCursor::pos() );
    11. delete contextMenu;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. private:
    2. void contextMenuEvent ( QContextMenuEvent * );
    To copy to clipboard, switch view to plain text mode 

    ERROR:
    Qt Code:
    1. test.cpp:21:23: Q3PopupMenu: No such file or directory
    2. test.cpp: In member function `virtual void MainWindow::contextMenuEvent(QContext
    3. MenuEvent*)':
    4. test.cpp:217: error: invalid use of undefined type `struct Q3PopupMenu'
    5. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/widgets/qmenu.h:359: error: forward
    6. declaration of `struct Q3PopupMenu'
    7. test.cpp:222: error: invalid use of undefined type `struct Q3PopupMenu'
    8. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/widgets/qmenu.h:359: error: forward
    9. declaration of `struct Q3PopupMenu'
    10. test.cpp:223: error: invalid use of undefined type `struct Q3PopupMenu'
    11. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/widgets/qmenu.h:359: error: forward
    12. declaration of `struct Q3PopupMenu'
    13. test.cpp:224: error: invalid use of undefined type `struct Q3PopupMenu'
    14. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/widgets/qmenu.h:359: error: forward
    15. declaration of `struct Q3PopupMenu'
    16. test.cpp:225: warning: possible problem detected in invocation of delete operato
    17. r:
    18. test.cpp:217: warning: `contextMenu' has incomplete type
    19. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/widgets/qmenu.h:359: warning: forwa
    20. rd declaration of `struct Q3PopupMenu'
    21. test.cpp:225: note: neither the destructor nor the class-specific operator delet
    22. e will be called, even if they are declared when the class is defined.
    23. mingw32-make[1]: *** [release\test.o] Error 1
    24. mingw32-make[1]: Leaving directory `D:/rapha/qtprojekte/qt4/mainwindowTableModel
    25. /ver3'
    26. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    I used this code on QT3 in my app. I have not found a example for QT4. Could be that in QT4 is easier, but i found nothing.
    If somebody have a example for QT4, why not
    Think DigitalGasoline

  2. #2
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Q3PopupMenu

    hi,
    Instead of writing Q3PopupMenu, just write QPopupMenu and try the code. That will work and also don't forget to write :
    #include <qpopupmenu.h>

    As far asthe examples in QT3 are concerned, no where it is mentioned as Q3PopupMenu. You can find the example in the following file:
    <qt-directory>/examples/menu/menu.cpp

    Please let me know the result.

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Q3PopupMenu

    have you this line in your *.cpp ?
    Qt Code:
    1. #include <Q3PopupMenu>
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  4. #4
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Q3PopupMenu

    No. It is mentioned as :
    #include <qpopupmenu.h>

  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi everybody!

    zlatko: yes i have

    both: i read that: For most purposes, QPopupMenu has been replaced by QMenu in Qt 4.
    I tyied now and it works
    Qt Code:
    1. QMenu* contextMenu = new QMenu( this );
    2. Q_CHECK_PTR( contextMenu );
    3. contextMenu->addAction( "&einfügen", this, SLOT(selectTable()) );
    4. contextMenu->exec( QCursor::pos() );
    5. delete contextMenu;
    To copy to clipboard, switch view to plain text mode 
    But the menu should just be called inside my QTableView and i am crashing my mind
    Where could i find more informations or examples for that
    Think DigitalGasoline

  6. #6
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Q3PopupMenu

    try reinplement in QTableWidget contextMenuEvent
    a life without programming is like an empty bottle

  7. #7
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi zlatko,
    Can you give me more information what you mean?
    Think DigitalGasoline

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,507 Times in 1,384 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q3PopupMenu

    Quote Originally Posted by raphaelf
    But the menu should just be called inside my QTableView and i am crashing my mind
    Where could i find more informations or examples for that
    Override table view's contextMenuEvent instead of MainWindow's.. (or use an event filter).

  9. #9
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Q3PopupMenu

    Quote Originally Posted by raphaelf
    Hi zlatko,
    Can you give me more information what you mean?
    Create class inherited from QTableView, alike QTableViewMy..and reinplement contextMenuEvent( QContextMenuEvent * )..ant then call menu exec from it.


    p.s. also look in jpn post, dont forget that you can use eventFilter instead of sublassing
    Last edited by zlatko; 6th March 2006 at 13:14.
    a life without programming is like an empty bottle

  10. #10
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi!
    eventfilter looks to be easier like subclass it

    I have tried to use it, but i dont have understand 100% how to use it,
    please help me to understand

    test.h:
    Qt Code:
    1. .
    2. .
    3. protected:
    4. bool eventFilter( QObject *o, QEvent *e );
    To copy to clipboard, switch view to plain text mode 

    test.cpp:
    Qt Code:
    1. MainWindow::MainWindow()
    2.  
    3. {
    4. ui.setupUi(this);
    5.  
    6. ui.tree->installEventFilter(this);
    7.  
    8.  
    9. // connect(ui.tabellen_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(selectTable()));
    10. connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(openLoginDialog()));
    11. connect(ui.actionNeu, SIGNAL(triggered()), this, SLOT(insertNewRow()));
    12. connect(ui.tree, SIGNAL(itemDoubleClicked( QTreeWidgetItem*, int)), this, SLOT(selectTable()));
    13.  
    14. init();
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::contextMenuEvent( QContextMenuEvent * )
    2. {
    3. QMenu* contextMenu = new QMenu( this );
    4. Q_CHECK_PTR( contextMenu );
    5. contextMenu->addAction( "&datensatz einfügen", this, SLOT(insertNewRow()) );
    6. contextMenu->addAction( "&datensatz löschen", this, SLOT(deleteRow()) );
    7. contextMenu->exec( QCursor::pos() );
    8. delete contextMenu;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool MainWindow::eventFilter( QObject *o, QEvent *e )
    2. {
    3.  
    4. if (event->type() == QEvent::ContextMenu)
    5. {
    6.  
    7. return true;
    8.  
    9. }
    10. else
    11. {
    12.  
    13. return false;
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    What is missing. Or what is false?
    Think DigitalGasoline

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,507 Times in 1,384 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q3PopupMenu

    You can use the same way for showing a context menu, as you used in MainWindow::contextMenuEvent

    Qt Code:
    1. if (event->type() == QEvent::ContextMenu)
    2. {
    3. // you may cast the event to appropriate type:
    4. QContextMenuEvent* menuevent = static_cast<QContextMenuEvent*>(event);
    5.  
    6. // (construct and) show your context menu here:
    7. contextMenu->exec(menuevent->globalPos());
    8. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi!
    It works!

    Qt Code:
    1. bool MainWindow::eventFilter( QObject *o, QEvent *event )
    2. {
    3.  
    4. if (event->type() == QEvent::ContextMenu)
    5. {
    6.  
    7. QContextMenuEvent* menuevent = static_cast<QContextMenuEvent*>(event);
    8.  
    9. QMenu* contextMenu = new QMenu( this );
    10. Q_CHECK_PTR( contextMenu );
    11. contextMenu->addAction( "&datensatz einfügen", this, SLOT(insertNewRow()) );
    12. contextMenu->addAction( "&datensatz löschen", this, SLOT(deleteRow()) );
    13. contextMenu->exec(menuevent->globalPos());
    14. delete contextMenu;
    15. }
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    If i have understand with "xxx->installEventFilter(this);" i enable a event for Object xxx
    Think DigitalGasoline

  13. #13
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi
    I found a bug!!!

    If i change my column width the values stay (see picutre).

    If i comment this line, it works
    Qt Code:
    1. ui.tableView->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    Oh, sheet, what should i do now?I dont think thats a qt bug
    Attached Images Attached Images
    Think DigitalGasoline

  14. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,507 Times in 1,384 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q3PopupMenu

    The event filter function should return a value:
    bool MainWindow::eventFilter( QObject *o, QEvent *event )

    From docs:
    In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
    ..so make it return false

  15. #15
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Q3PopupMenu

    in other words
    Qt Code:
    1. if (event->type() == QEvent::ContextMenu)
    2. {
    3. QContextMenuEvent* menuevent = static_cast<QContextMenuEvent*>(event);
    4.  
    5. QMenu* contextMenu = new QMenu( this );
    6. Q_CHECK_PTR( contextMenu );
    7. contextMenu->addAction( "&datensatz einfügen", this, SLOT(insertNewRow()) );
    8. contextMenu->addAction( "&datensatz löschen", this, SLOT(deleteRow()) );
    9. contextMenu->exec(menuevent->globalPos());
    10. delete contextMenu;
    11. return true;
    12. }
    13. else
    14. return false;
    To copy to clipboard, switch view to plain text mode 

    I think your compilator give you something alike that warning : not of all control block retun value
    a life without programming is like an empty bottle

  16. #16
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Q3PopupMenu

    Hi Guys!
    ufff

    Thanks it looks to work perfect now

    zlatko: yes there was a warning
    Think DigitalGasoline

+ Reply to Thread

Similar Threads

  1. Q3PopupMenu
    By user_mail07 in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 08:52
  2. Q3PopUpmenu: Qchar * to QString
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2007, 20:33
  3. Q3PopupMenu - unsupported method issue
    By Amanda in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 10:11

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