Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I can't handle doubleClicked signal but clicked work well in using QListView,why?
Forum Updated to NodeBB v4.3 + New Features

I can't handle doubleClicked signal but clicked work well in using QListView,why?

Scheduled Pinned Locked Moved General and Desktop
17 Posts 3 Posters 10.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    henryxuv
    wrote on last edited by
    #1

    I write code in construction function of my own class which subclass from QListView.
    @
    connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex))); //works properly.
    connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex)));//doesn't work
    @
    I just can handle the clicked signal but doubleClicked ,Can anybody tell me why?
    My Qt SDK version is 4.7. development enviroment is Win7, Qt Creator

    Edit: added @ tags around the code. You can edit your post if needed to correct mistakes; Andre

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      The doubleClicked() signal is triggered for me in the example below. Does the example below reproduce your problem? If not, can you modify it so that it does?

      @#include <QtGui>

      class ListView : public QListView
      {
      Q_OBJECT

      public:
      ListView()
      {
      QStringList list;
      list << "first" << "second" << "third" << "fourth" << "fith" << "sixth";
      QStringListModel *myModel = new QStringListModel(this);

      myModel->setStringList(list);
      setModel(myModel);
      connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex)));
      connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedSlot(QModelIndex)));
      }
      public slots:
      void myItemSelected(QModelIndex)
      {
      qDebug() << "Clicked was triggered";
      }

      void doubleClickedSlot(QModelIndex)
      {
      qDebug() << "Double clicked was triggered";
      }
      };
      #include "main.moc"

      int main(int argc, char** argv)
      {
      QApplication app(argc, argv);
      ListView view;
      view.show();
      return app.exec();

      }@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        I see no reason at all why it wouldn't work, and I have used this signal myself too without any problems. Are you absolutely positive that you did not make some small mistake in the connect statement in your real code?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          henryxuv
          wrote on last edited by
          #4

          Thank you very much, Andre. your code is really work well . But my code is a little complicated. The class which subclass from QListView, It's object is decorated with QGraphicsProxyWidget to be layout into a QGraphicsWidget object. and then the doubleClicked signal cannot be handled. without the QGraphicsProxyWidget my code could receive the signal too. I am trying to solve it. If you have some advice for this issue , I will be grateful.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            henryxuv
            wrote on last edited by
            #5

            [quote author="sigrid" date="1305096445"]The doubleClicked() signal is triggered for me in the example below. Does the example below reproduce your problem? If not, can you modify it so that it does? @#include <QtGui> class ListView : public QListView { Q_OBJECT public: ListView() { QStringList list; list << "first" << "second" << "third" << "fourth" << "fith" << "sixth"; QStringListModel myModel = new QStringListModel(this); myModel->setStringList(list); setModel(myModel); connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex))); connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedSlot(QModelIndex))); } public slots: void myItemSelected(QModelIndex) { qDebug() << "Clicked was triggered"; } void doubleClickedSlot(QModelIndex) { qDebug() << "Double clicked was triggered"; } }; #include "main.moc" int main(int argc, char* argv) { QApplication app(argc, argv); ListView view; view.show(); return app.exec(); }@[/quote]
            Thank you very much. your code is really work well . But my code is a little complicated. The class which subclass from QListView, It’s object is decorated with QGraphicsProxyWidget to be layout into a QGraphicsWidget object. and then the doubleClicked signal cannot be handled. without the QGraphicsProxyWidget my code could receive the signal too. I am trying to solve it. If you have some advice for this issue , I will be grateful.
            .

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              QGraphicsProxyWidget is a problematic thing, it seems. It never quite worked properly, and as I gathered, it is considdered to be failed experiment.

              What you might considder, is if you could use a QML ListView element in your view instead of a a QWidget based one. That way, you could avoid using QGraphicsProxyWidget and all the problems it brings with it.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                henryxuv
                wrote on last edited by
                #7

                [quote author="Andre" date="1305100976"]QGraphicsProxyWidget is a problematic thing, it seems. It never quite worked properly, and as I gathered, it is considdered to be failed experiment. What you might considder, is if you could use a QML ListView element in your view instead of a a QWidget based one. That way, you could avoid using QGraphicsProxyWidget and all the problems it brings with it. [/quote]

                Alright , I will consider it. I am really grateful for your reply.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sigrid
                  wrote on last edited by
                  #8

                  bq. Thank you very much. your code is really work well . But my code is a little complicated. The class which subclass from QListView, It’s object is decorated with QGraphicsProxyWidget to be layout into a QGraphicsWidget object. and then the doubleClicked signal cannot be handled. without the QGraphicsProxyWidget my code could receive the signal too. I am trying to solve it. If you have some advice for this issue , I will be grateful.

                  I am a bit confused. Can you let me know whether your QListView is embedded in a QGraphicsProxyWidget, or whether you have QGraphicsProxyWidgets as items in your view?

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    henryxuv
                    wrote on last edited by
                    #9

                    [quote author="sigrid" date="1305111509"]bq. I am a bit confused. Can you let me know whether your QListView is embedded in a QGraphicsProxyWidget, or whether you have QGraphicsProxyWidgets as items in your view? [/quote]
                    Yes my QListView is embedded in a QGraphicsProxyWidget, and this QGraphicsProxyWidget was added into a QGraphicsWidget.and then QGraphicsWidget is showed in a QGraphicsView.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sigrid
                      wrote on last edited by
                      #10

                      I see. The doubleClicked() signal is still triggered for me when following the approach you describe above. Does the example below reproduce your problem? If not, can you modify it so that it does?

                      @#include <QtGui>

                      class ListView : public QListView
                      {
                      Q_OBJECT

                      public:
                      ListView()
                      {
                      QStringList list;
                      list << "first" << "second" << "third" << "fourth" << "fith" << "sixth";
                      QStringListModel *myModel = new QStringListModel(this);

                      myModel->setStringList(list);
                      setModel(myModel);
                      connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex)));
                      connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedSlot(QModelIndex)));
                      }
                      public slots:
                      void myItemSelected(QModelIndex)
                      {
                      qDebug() << "Clicked was triggered";
                      }

                      void doubleClickedSlot(QModelIndex)
                      {
                      qDebug() << "Double clicked was triggered";
                      }
                      };
                      #include "main.moc"

                      int main(int argc, char** argv)
                      {
                      QApplication app(argc, argv);
                      QGraphicsView view;
                      QGraphicsScene scene;
                      ListView *listView = new ListView;
                      QGraphicsWidget *widget = new QGraphicsWidget();
                      QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(widget);
                      proxy->setWidget(listView);

                      scene.addItem(widget);
                      view.setScene(&scene);
                      view.show();
                      return app.exec();

                      }@

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        henryxuv
                        wrote on last edited by
                        #11

                        Ok , Indeed the problem is mine not the QGraphicsProxyWidget. because I reimplemented the mouseDoubleClickEvent function of QGraphicsView. So when I double clicked the QListView widget. the signal was send to my QGraphicsView not the QListView. As a result, I lost my doubleClicked signal.Here is my sample code. Do you have solution for this situation? I am a new guy to QT.
                        @
                        #include <QtGui/QApplication>
                        #include <QListView>
                        #include <QGraphicsView>
                        #include <QStringList>
                        #include <QStringListModel>
                        #include <QDebug>
                        #include <QGraphicsWidget>
                        #include <QGraphicsProxyWidget>
                        #include <QGraphicsGridLayout>
                        #include <QDirModel>
                        #include <QPushButton>
                        class ListView : public QListView
                        {
                        Q_OBJECT
                        public:
                        ListView()
                        {
                        QStringList list;
                        list << "first" << "second" << "third" << "fourth" << "fith" << "sixth";
                        QStringListModel *myModel = new QStringListModel(this);
                        myModel->setStringList(list);
                        //setModel(myModel);
                        setModel(new QDirModel());
                        connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex)));
                        connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedSlot(QModelIndex))); }
                        public slots:
                        void myItemSelected(QModelIndex)
                        {
                        qDebug() << "Clicked was triggered";
                        }
                        void doubleClickedSlot(QModelIndex)
                        {
                        qDebug() << "Double clicked was triggered";
                        }
                        };
                        class GraphicsView:public QGraphicsView
                        {
                        public:
                        GraphicsView(QWidget * parent = 0):QGraphicsView(parent)
                        {

                        }
                        
                        void mouseDoubleClickEvent(QMouseEvent *event)
                        {
                            // do something.
                            return;
                        }
                        

                        };

                        #include "debug/main.moc"
                        int main(int argc, char *argv[])
                        {
                        QApplication a(argc, argv);

                        GraphicsView view;
                        QGraphicsScene scene;
                        ListView *listView = new ListView;
                        QGraphicsWidget *widget = new QGraphicsWidget();    
                        QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
                        proxy->setWidget(listView);
                        QGraphicsGridLayout *pLayout = new QGraphicsGridLayout();
                        pLayout->addItem(proxy,0,0);
                        widget->setLayout(pLayout);
                        scene.addItem(widget);
                        view.setScene(&scene);
                        view.show();
                        
                        return a.exec(&#41;;
                        

                        }
                        @

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          henryxuv
                          wrote on last edited by
                          #12

                          [quote author="sigrid" date="1305183595"]I see. The doubleClicked() signal is still triggered for me when following the approach you describe above. Does the example below reproduce your problem? If not, can you modify it so that it does?
                          @
                          #include <QtGui> class ListView : public QListView
                          {
                          Q_OBJECT
                          public:
                          ListView()
                          {
                          QStringList list;
                          list << "first" << "second" << "third" << "fourth" << "fith" << "sixth";
                          QStringListModel *myModel = new QStringListModel(this);
                          myModel->setStringList(list);
                          setModel(myModel);
                          connect(this, SIGNAL(clicked(QModelIndex)),this,SLOT(myItemSelected(QModelIndex)));
                          connect(this, SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedSlot(QModelIndex)));
                          }

                          public slots:
                          void myItemSelected(QModelIndex)
                          {
                          qDebug() << "Clicked was triggered";
                          }
                          void doubleClickedSlot(QModelIndex)
                          {
                          qDebug() << "Double clicked was triggered";
                          }
                          };

                          #include "main.moc"

                          int main(int argc, char** argv)
                          {
                          QApplication app(argc, argv);
                          QGraphicsView view;
                          QGraphicsScene scene;
                          ListView *listView = new ListView;
                          QGraphicsWidget *widget = new QGraphicsWidget();
                          QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(widget);
                          proxy->setWidget(listView);
                          scene.addItem(widget);
                          view.setScene(&scene);
                          view.show();
                          return app.exec();
                          }
                          @

                          [/quote]

                          Here is my code, thank you for your patience

                          Edit: fixed-up code formatting; Andre

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            sigrid
                            wrote on last edited by
                            #13

                            You can call the base class before you do your own stuff in the mouseDoubleClickEvent(), something like:

                            @
                            void mouseDoubleClickEvent(QMouseEvent *event)
                            {
                            QGraphicsView::mouseDoubleClickEvent(event);
                            // do something.
                            return;
                            }
                            @

                            Does that give you the behavior you need?

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              henryxuv
                              wrote on last edited by
                              #14

                              [quote author="sigrid" date="1305207781"]You can call the base class before you do your own stuff in the mouseDoubleClickEvent(), something like: @ void mouseDoubleClickEvent(QMouseEvent *event) { QGraphicsView::mouseDoubleClickEvent(event); // do something. return; } @ Does that give you the behavior you need?[/quote]

                              finally, It works. Thank you very much. I just have no idea why I need to call mouseDoubleClickEvent of the base class . Do I neglect something in Qt Helper?Can you recommend some article about this?

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                sigrid
                                wrote on last edited by
                                #15

                                The view receives input events from the keyboard and mouse, and translates these to scene events. The scene is responsible of propagating the events to the items on the scene, and if you don't call the base class, then the internal code which propagates the event will not be called and hence your signal not triggered, you can find documentation on this here:

                                http://doc.qt.nokia.com/4.7/graphicsview.html

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #16

                                  Calling the base class implementation of a function you reimplement is usually a good idea. Unless you are certain that you completely want to override everything the base class did (or you know it does nothing), you should call the base implementation by default.

                                  1 Reply Last reply
                                  0
                                  • H Offline
                                    H Offline
                                    henryxuv
                                    wrote on last edited by
                                    #17

                                    [quote author="Andre" date="1305271263"]Calling the base class implementation of a function you reimplement is usually a good idea. Unless you are certain that you completely want to override everything the base class did (or you know it does nothing), you should call the base implementation by default. [/quote]
                                    Lots of thanks to both Andred and sigrid.. this forum is really paradis for Qt users

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved