PDA

View Full Version : QTableView doubleclicked event not working



sgmurphy19
24th August 2007, 14:44
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-programming-2/t-qt-table-model-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:


void Gui::showAtriumForm()
{
atriumForm = new QMainWindow;
AtriumForm = new Ui_AtriumForm;
AtriumForm->setupUi(atriumForm);
atriumForm->show();

connect(AtriumForm->collectionsView, SIGNAL(doubleclicked(QModelIndex)), this, SLOT(rowDoubleClicked(QModelIndex)));
}


void Gui::rowDoubleClicked(QModelIndex indx)
{
QMessageBox::information(NULL, "here", "Row was double clicked");
}

The model type sholdn't matter, correct? Here is where I set it.

QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT * FROM collection AS co LEFT JOIN collectors AS c ON co.Collector_ID=c.Collector_ID");
gui->AtriumForm->collectionsView->setModel(model);


All help is appreciated!
Sean

jacek
24th August 2007, 14:48
AtriumForm->setupUi(atriumForm);
Do you use two variables here or just one?


SIGNAL(doubleclicked(QModelIndex))
There is no such signal. It should be doubleClicked.

jpn
24th August 2007, 14:49
It's doubleClicked with an uppercase C. ;)

sgmurphy19
24th August 2007, 15:07
Thanks to you both! A couple hours of frustration came down to syntax! :) Any idea why no error occurred at compile?

jacek
24th August 2007, 16:31
Any idea why no error occurred at compile?
Because SIGNAL is defined this way:

#define SIGNAL(a) "2"#a
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.

ranna
9th January 2009, 12:23
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

jimholman49
15th March 2009, 10:00
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:


g_paScheduleTableModel = new AScheduleTableModel(m_paSchedule);
ui.m_pqScheduleTableView->setModel( g_paScheduleTableModel );

I make sure the edit triggers are set and may my connections:


ui.m_pqScheduleTableView->setEditTriggers(QAbstractItemView::AllEditTriggers );
connect(ui.m_pqScheduleTableView, SIGNAL(clicked(const QModelIndex&)), this,
SLOT(cellClicked(QModelIndex& )));
connect(ui.m_pqScheduleTableView, SIGNAL(doubleClicked( const QModelIndex&)), this, SLOT(cellDoubleClicked(const QModelIndex&)));

I receive the signals for "clicked" but I do not receive the signals "doubleClicked".

Any suggestions?