Results 1 to 7 of 7

Thread: QTableView doubleclicked event not working

  1. #1
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTableView doubleclicked event not working

    I am developing this using QT4.3.1 and on a Mac OS X with intel processor.

    Let me preface by saying I have read the posts:
    http://www.qtcentre.org/forum/faq.php?faq=qt_signalslot
    as well as
    http://www.qtcentre.org/forum/f-qt-p...odel-5276.html
    and that i get no compiling errors. I have also changed the doubleclicked(QModelIndex) to doubleclicked(QModelIndex&) and doubleclicked(QModelIndex &) and still no luck.

    My end objective is to have a user double click any row or cell within a QTableView and have some action as a result. But right now it appears that the double-click event is not working.

    I have a QTableView which is working because I can set it's model and display data.

    Right now all I expect to see is a message window, but I get nothing.

    Here is my code:

    Qt Code:
    1. void Gui::showAtriumForm()
    2. {
    3. atriumForm = new QMainWindow;
    4. AtriumForm = new Ui_AtriumForm;
    5. AtriumForm->setupUi(atriumForm);
    6. atriumForm->show();
    7.  
    8. connect(AtriumForm->collectionsView, SIGNAL(doubleclicked(QModelIndex)), this, SLOT(rowDoubleClicked(QModelIndex)));
    9. }
    10.  
    11.  
    12. void Gui::rowDoubleClicked(QModelIndex indx)
    13. {
    14. QMessageBox::information(NULL, "here", "Row was double clicked");
    15. }
    To copy to clipboard, switch view to plain text mode 

    The model type sholdn't matter, correct? Here is where I set it.
    Qt Code:
    1. model->setQuery("SELECT * FROM collection AS co LEFT JOIN collectors AS c ON co.Collector_ID=c.Collector_ID");
    2. gui->AtriumForm->collectionsView->setModel(model);
    To copy to clipboard, switch view to plain text mode 


    All help is appreciated!
    Sean
    Last edited by jpn; 15th March 2009 at 10:41. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView doubleclicked event not working

    Quote Originally Posted by sgmurphy19 View Post
    AtriumForm->setupUi(atriumForm);
    Do you use two variables here or just one?

    Quote Originally Posted by sgmurphy19 View Post
    SIGNAL(doubleclicked(QModelIndex))
    There is no such signal. It should be doubleClicked.
    Last edited by jacek; 24th August 2007 at 14:57. Reason: typo

  3. The following user says thank you to jacek for this useful post:

    sgmurphy19 (24th August 2007)

  4. #3
    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: QTableView doubleclicked event not working

    It's doubleClicked with an uppercase C.
    J-P Nurmi

  5. #4
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTableView doubleclicked event not working

    Thanks to you both! A couple hours of frustration came down to syntax! Any idea why no error occurred at compile?

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView doubleclicked event not working

    Quote Originally Posted by sgmurphy19 View Post
    Any idea why no error occurred at compile?
    Because SIGNAL is defined this way:
    Qt Code:
    1. #define SIGNAL(a) "2"#a
    To copy to clipboard, switch view to plain text mode 
    In other words, you pass strings to connect, not methods, so compiler can't check them. Although such errors can be detected at runtime, if you compile your application in debug mode and look at the console.

  7. #6
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: QTableView doubleclicked event not working

    i think by default the doubleClicked signal makes the currend index to be selected in edit mode. But i am using QT 4.4 and i dont know have any idea on other versions

    You can try this

    QObject::connect(this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(edit(const QModelIndex &)));

    I hope it will work. Once you double click in a cell it will be in edit mode but before emitting the double clicked signal (manually) you have to select the iindex by
    this->setCurrentIndex(index);

    Note: "this" is a object of QTableView. Lets see what happends

  8. #7
    Join Date
    Mar 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView doubleclicked event not working

    I wonder if anybody can help me. I'm having a similar problem with not being able to get "doubleClicked" to work on a QTableView. I'm using Qt 4.5.0 (commercial) on Windows XP.

    I have a simple form with a QTableView. I create and set my model as follows:

    Qt Code:
    1. g_paScheduleTableModel = new AScheduleTableModel(m_paSchedule);
    2. ui.m_pqScheduleTableView->setModel( g_paScheduleTableModel );
    To copy to clipboard, switch view to plain text mode 
    I make sure the edit triggers are set and may my connections:

    Qt Code:
    1. ui.m_pqScheduleTableView->setEditTriggers(QAbstractItemView::AllEditTriggers);
    2. connect(ui.m_pqScheduleTableView, SIGNAL(clicked(const QModelIndex&)), this,
    3. SLOT(cellClicked(QModelIndex& )));
    4. connect(ui.m_pqScheduleTableView, SIGNAL(doubleClicked( const QModelIndex&)), this, SLOT(cellDoubleClicked(const QModelIndex&)));
    To copy to clipboard, switch view to plain text mode 
    I receive the signals for "clicked" but I do not receive the signals "doubleClicked".

    Any suggestions?
    Last edited by jpn; 15th March 2009 at 10:39. Reason: missing [code] tags

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.