Results 1 to 17 of 17

Thread: QItemDelegate Context Menu

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QItemDelegate Context Menu

    Dear All

    We have a QTableWidget and we make a delegate for this. For one of the coloumn we need a context menu. We could bring a context menu but the problem is context menu is not standart. Is there a solution for this, or can you make a sugestion for this?

    Please help

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Context Menu

    Delegate has nothing to do with context menus. You have to do that in the view like for any other widget.

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    What I mean is like this

    In my delegate fuction I have createActions to create action which changes in every row.

    Qt Code:
    1. void ProformaDelegate::createActions()
    2. {
    3.  
    4. QSqlQuery fiyat_tipleri;
    5. fiyat_tipleri.exec("SELECT id, stokid from table where if = '" + xxx +"';");
    6. int i = 0;
    7. while(fiyat_tipleri.next()){
    8.  
    9. recentFileActs[i] = new QAction(fiyat_tipleri.value(3).toString(), this);
    10.  
    11. ++i;
    12. sayi = i;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    And in createEditor part I ask for the delegate.

    Qt Code:
    1. else if(index.column() == 5 || index.column() == 8)
    2. {
    3.  
    4. MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
    5. editor->setMinimum(0);
    6. editor->setMaximum(4000000000);
    7. editor->setDecimals(4);
    8. editor->setSuffix(" " + totalParaBirimi);
    9. editor->setAlignment(Qt::AlignRight);
    10.  
    11. for (int i = 0; i < sayi; ++i)
    12. editor->addAction(recentFileActs[i]);
    13. editor->setContextMenuPolicy(Qt::ActionsContextMenu);
    14.  
    15. return editor;
    16. }
    To copy to clipboard, switch view to plain text mode 

    The problem is I could not start createActions() functions from createEditor() part, and also send information (xxx) for the SQL query

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Context Menu

    What do you mean you couldn't start it? It doesn't compile or you don't see the result or...? BTW. I think your SQL statement is invalid - 'if' is probably a function name which may cause a clash with a database field with the same name if you have one.

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    I dont have a problem in compiling.

    But what I want to do is everytime I come to column 5 of column 8 I want the delegate start fuction createActions(), but when I write like this
    Qt Code:
    1. if(index.column() == 5 || index.column() == 8)
    2.  
    3. {
    4. MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
    5. editor->setMinimum(0);
    6. editor->setMaximum(4000000000);
    7. editor->setDecimals(4);
    8. editor->setSuffix(" " + totalParaBirimi);
    9. editor->setAlignment(Qt::AlignRight);
    10.  
    11. createActions();
    12.  
    13. for (int i = 0; i < sayi; ++i)
    14. editor->addAction(recentFileActs[i]);
    15. editor->setContextMenuPolicy(Qt::ActionsContextMenu);
    16.  
    17. return editor;
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    I could not compile it. I get a error like

    error: passing `const ProformaDelegate'
    as `this' argument of `void ProformaDelegate::createActions()' discards qualifie
    rs

  6. #6
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    any idea? How can I do it?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Context Menu

    In general you shouldn't do it this way or you should make your createActions() method const.

  8. #8
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    I understand,

    But can you help me how can I do it?

    What I would like to do is,

    Think about a qtablewidget,

    for every row there are different data. For everydata (for every row) I would like to biring a information from SQL, when context menu requested, I need to run sql query with a data on the row and bring information for the row with context.

    Can you help?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Context Menu

    Reimplement contextMenuEvent() from QTableWidget.

  10. #10
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    any example you could help me?

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

    Default Re: QItemDelegate Context Menu

    Quote Originally Posted by aekilic View Post
    any example you could help me?
    http://www.qtcentre.org/forum/p-drag...ostcount2.html
    J-P Nurmi

  12. #12
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    the problem I have now is,

    I could use

    connect(tableProformaindex, SIGNAL(customContextMenuRequested (QPoint)), this, SLOT(createActions(QPoint)));

    but after the window open it works one time, but after that it never works.

  13. #13
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    any thing you could help me?

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

    Default Re: QItemDelegate Context Menu

    Quote Originally Posted by aekilic View Post
    the problem I have now is,

    I could use

    connect(tableProformaindex, SIGNAL(customContextMenuRequested (QPoint)), this, SLOT(createActions(QPoint)));

    but after the window open it works one time, but after that it never works.
    There is no way we can help you unless you show the relevant code.
    J-P Nurmi

  15. #15
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Context Menu

    Dear Jpn

    What we are trying to is, for every row of a QTableWidget, we need a new menu...

    Is there a way that we could do it?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Context Menu

    Yes, create a regular context menu In the event handler create an instance of QMenu, assign it the actions you want to show and call QMenu::exec(). And please read the docs.

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

    Default Re: QItemDelegate Context Menu

    Quote Originally Posted by aekilic View Post
    What we are trying to is, for every row of a QTableWidget, we need a new menu...

    Is there a way that we could do it?
    I have already posted a link which shows an example how to do it. Use QTableWidget::itemAt() to get the item below requested point. Here's one more example with signals and slots: http://www.qtcentre.org/forum/p-qlis...ostcount5.html
    J-P Nurmi

Similar Threads

  1. QTabBar - Context menu on tab
    By gruszczy in forum Qt Programming
    Replies: 5
    Last Post: 3rd July 2020, 13:33
  2. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  3. QTable context menu
    By grabnerj in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2008, 05:20
  4. context menu problem
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 13:18
  5. Replies: 4
    Last Post: 25th June 2007, 20:40

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.