In my application, I've got a popup table that pops up when the user presses a 
key (in this case CTRL), and goes away when the user releases the key. While 
the table is visible, the user can click on rows to highlight a row. When the 
user highlights an item, a signal should be emitted from the table widget, and 
then another part of the application should mirror the highlighting action.

What I'm finding is that while the table is up, the signal to the parent class 
seems to just be getting queued, and the signal never propagates out UNTIL the 
key is released. So the action I'm looking for eventually occurs, but is 
delayed. Any ideas on how to get the signal acted on immediately? Relevant 
pseudocode below:

class MainWindow : public QMainWindow
{
public slots:
    void slotDoOtherStuff(QString, bool);

protected:
    virtual void keyPressEvent(QKeyEvent* event);
    virtual void keyReleaseEvent(QKeyEvent* event);

private:
    QTableView* dataTable;
    myModel* dataTableModel;
}

void MainWindow:: MainWindow (QWidget *parent)
{
      dataTable = new QTableView(this);
      dataTableModel = new myModel(this);
      dataTable->setModel(dataTableModel);
      connect(dataTableModel, SIGNAL(sigItemClicked(QString,bool)),
                this, SLOT(slotDoOtherStuff (QString,bool)));
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    QMainWindow::keyPressEvent(event);
    if (event->key() == mPopupKey)
    {
       //populate table here
      dataTable->show();
}

void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
    QMainWindow::keyPressEvent(event);
    if (event->key() == mPopupKey)
    {
        dataTable ->hide();
    }
}

void MainWindow:: slotDoOtherStuff(QString,bool) 
{
    QMainWindow::keyPressEvent(event);
    if (event->key() == mPopupKey)
    {
       //populate table here
      dataTable->show();
}

So in the pseudocode above, while the table is shown (i.e. while the CTRL key 
is held down), slotDoOtherStuff() never gets called until after the popup key 
is released. Then however many sigItemClicked() signals that were queued up are 
finally acted upon. So it looks like while the key is pressed, that part of the 
event loop isn't spinning? But the user can interact with the popup table while 
the key is pressed, so some part of the event loop is still active...

Sean

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to