Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Sending simulated key events through QX11EmbedContainer

$
0
0
Hi everyone! I have a “server”(the qx11embedcontainer) and a client(qx11embedwidget) and using Qt 4.8.1. Embedding the client works fine, except for when I try to send programmed key events from the server to the client. When I click my “tab” button on the server side, it changes focus each time until it reaches the _container for xembed. If the container has focus, when I now post a tab key event this event will be sent to the client. When the client receives a key event from this post and print the key value, it will always be the last key value I pressed on my keyboard when the client had focus. The KeyPress and KeyRelease on my keyevents are ignored as well and seems be the the last one from the keyboard. That is the programmed key event from my “tab” button will be received, but it’s value will be something it shouldn’t. Have anyone got an idea what is wrong with this code? // Server class Test : public QWidget {  Q_OBJECT public:  Test() : QWidget( 0 )  {   QVBoxLayout *l = new QVBoxLayout( this );     _container = new QX11EmbedContainer();   _container->setFocusPolicy(Qt::StrongFocus);   _winId = new QLineEdit();   _winId->setFocusPolicy(Qt::StrongFocus);     QPushButton *b = new QPushButton( "Embed" );   b->setFocusPolicy(Qt::StrongFocus);     QPushButton *tab = new QPushButton( "Tab" );   tab->setFocusPolicy(Qt::NoFocus);     l->addWidget( _container );   l->addWidget( _winId );   l->addWidget( b );   l->addWidget(tab);     setLayout( l );     connect( tab, SIGNAL( pressed() ),     this, SLOT( slotPressedTab() ) );   connect( tab, SIGNAL( released() ),     this, SLOT( slotReleasedTab() ) );     connect( b, SIGNAL( clicked() ),     this, SLOT( embed() ) );     connect( _container, SIGNAL( error( QX11EmbedContainer::Error ) ),     this, SLOT( error( QX11EmbedContainer::Error ) ) );  }    private slots:  void slotPressedTab() {   QCoreApplication::postEvent(this->focusWidget(), new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Tab, 0, 0));  }  void slotReleasedTab() {   QCoreApplication::postEvent(this->focusWidget(), new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Tab, 0, 0));  }    void embed() {   WId id = _winId->text().toInt(0,10);//.toUInt( 0, 16 ); // note: base 16!   std::cout << "THE ID IS:" << id << std::endl;   _container->embedClient( id );  }    void error( QX11EmbedContainer::Error err ) {   QMessageBox::warning( this, "Error", QString::number( err ) );  }    private:  QX11EmbedContainer *_container;  QLineEdit *_winId; }; // Client class MyWindow : public QX11EmbedWidget {  Q_OBJECT public:  MyWindow(QWidget* parent=0) : QX11EmbedWidget(parent) {   isEmbedded = false;   setFixedSize(QSize(200,200));     label = new QLabel();   label->setText(QString("test test test"));     lineEdit = new QLineEdit();     QPushButton* button = new QPushButton();     QHBoxLayout *layout = new QHBoxLayout(this);     layout->addWidget(label);   layout->addWidget(lineEdit);   layout->addWidget(button);     qDebug("window id:%lu", winId());  };  QLabel *label;  QLineEdit *lineEdit;    bool eventFilter(QObject *object, QEvent *event) {   if (event->type() == QEvent::KeyPress) {    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);    qDebug("another key in event pressed filter: %i", keyEvent->key());    }   } else if (event->type() == QEvent::KeyRelease) {    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);    qDebug("another key in event release filter: %i", keyEvent->key());   }     return QX11EmbedWidget::eventFilter(object, event);  } Note I haven’t added the error signal slots and such here for convenience but they are not printing any errors.

Viewing all articles
Browse latest Browse all 13965

Trending Articles