Results 1 to 10 of 10

Thread: QComboBox Item Right Click

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question QComboBox Item Right Click

    How to catch rightclick event on QComboBox item? I tried reimplement mousePressEvent for my custom combobox, but not luck The event just for ComboBox it self, not for Item.

  2. #2
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    http://doc.qt.digia.com/qt/qcombobox...etItemDelegate implement own QAbstractItemDelegate and implement own events. Afte that set item delegate. And wala it will work

  3. #3
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question Re: QComboBox Item Right Click

    Can I use mousePressEvent in abstractitemdelegate?

    Btw, I want make different emit signal for left and right click on combobox item.

  4. #4
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    Yes of course and now example for mouseevent:
    Qt Code:
    1. void mouseReleaseEvent ( QMouseEvent * event )
    2. {
    3. if(event->button() == Qt::RightButton)
    4. {
    5. emit rightClick();
    6. }
    7. if(event->button() == Qt::LeftButton)
    8. {
    9. emit leftClick();
    10. }
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 
    You can use mouseReleaseEvent or MousePressEvent
    Last edited by Viper666; 13th January 2013 at 11:55.

  5. #5
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    Not work

    Qt Code:
    1. void ComboBoxDelegate::mousePressEvent(QMouseEvent *e)
    2. {
    3. if (e->button()==Qt::LeftButton) {
    4. qDebug() << "Klik Kiri";
    5. }
    6.  
    7. if (e->button()==Qt::RightButton) {
    8. qDebug() << "Klik Kanan";
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Btw, how can I know index of item selected?

  6. #6
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    Oh sorry my mistake i mean QItemDelegate
    At first you must have working delegate like in this example http://programmingexamples.net/wiki/...mboBoxDelegate and when you own delegate works you can implement mouseEvent if it will not work post here you code.

  7. #7
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    Of course I use QItemDelegate. But not work

    Qt Code:
    1. #ifndef COMBOBOXDELEGATE_H
    2. #define COMBOBOXDELEGATE_H
    3.  
    4. #include <QItemDelegate>
    5.  
    6. class ComboBoxDelegate : public QItemDelegate
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit ComboBoxDelegate(QObject *parent = 0);
    11.  
    12. protected:
    13. void mousePressEvent(QMouseEvent *e);
    14.  
    15. signals:
    16.  
    17. public slots:
    18.  
    19. };
    20.  
    21. #endif // COMBOBOXDELEGATE_H
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "comboboxdelegate.h"
    2. #include <QMouseEvent>
    3. #include <QDebug>
    4.  
    5. ComboBoxDelegate::ComboBoxDelegate(QObject *parent) :
    6. QItemDelegate(parent)
    7. {
    8. }
    9.  
    10. void ComboBoxDelegate::mousePressEvent(QMouseEvent *e)
    11. {
    12. if (e->button()==Qt::LeftButton) {
    13. qDebug() << "Klik Kiri";
    14. }
    15.  
    16. if (e->button()==Qt::RightButton) {
    17. qDebug() << "Klik Kanan";
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    I only need catch mouse event. And get what item index is selected...

  8. #8
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    I will write a example for you. But now i can' sorry. I don't know why it doesn't work but i think it has some solution

  9. #9
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    Oh, no problem.
    Btw, thanks for your response

  10. #10
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Item Right Click

    ok i solved it.
    Solution: in QItemDelegate isn't mousePressEvent or something like that this are events from Qobject but this don't work for QItemDelegate you need implement editorEvent:
    Qt Code:
    1. bool Item::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    2. {
    3.  
    4. if (event->type() == QEvent::MouseButtonPress)
    5. {
    6. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    7. if(mouseEvent->button() == Qt::LeftButton)
    8. qDebug() << "leftButton";
    9.  
    10.  
    11.  
    12. if(mouseEvent->button() == Qt::RightButton)
    13. qDebug() << "rightButton";
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Viper666; 13th January 2013 at 21:30.

  11. The following user says thank you to Viper666 for this useful post:

    wirasto (13th January 2013)

Similar Threads

  1. Replies: 0
    Last Post: 10th March 2011, 11:44
  2. Searching an item in QCombobox
    By ramarolahyangelo in forum Newbie
    Replies: 2
    Last Post: 21st December 2010, 08:51
  3. QComboBox item disable?
    By Equilibrium in forum Qt Programming
    Replies: 8
    Last Post: 28th November 2007, 17:41
  4. QComboBox and item
    By drow in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2006, 09:04
  5. TreeView click item not connecting
    By Big Duck in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2006, 19:38

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.