Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3617

Focus problem with QX11EmbedWidget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.7
    • 4.4.3, 4.6.2
    • Core: Event loop
    • None
    • 4c7565056f94814d857f210cbda04919a88adc62

    Description

      When using QX11EmbedWidget and QX11EmbedContainer, there are certain situations where the QX11EmbedWidget will not receive focus. If for example you embed a QTextEdit, the mouse cursor will change to an I-bar, when you hover over the widget, but if you click, you will not get the blinking cursor, nor will you be able to input. The unusual thing though is that if you minimize->maximize the window, or alt+tab -> alt+shit+tab, then you will have input focus.

      I also have a small example that demonstrates this behavior. First you need to have Embedded Widget Implementation:

      #include <QWidget>
      #include <QVBoxLayout>
      #include <QTextEdit>
      #include <QX11EmbedWidget>
      #include <QApplication>
      
      class Widget : public QWidget
      {
      public:
          Widget(QWidget *parent = 0);
      };
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
      {
          QVBoxLayout *vbox = new QVBoxLayout(this);
          QTextEdit *edit = new QTextEdit(this);
          edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
          vbox->addWidget(edit);
          setLayout(vbox);
      }
      
      class EWidget : public QX11EmbedWidget
      {
      public:
          EWidget(QWidget *parent = 0);
      };
      
      EWidget::EWidget(QWidget *parent)
          : QX11EmbedWidget(parent)
      {
          QVBoxLayout *vbox = new QVBoxLayout(this);
          QTextEdit *edit = new QTextEdit(this);
          edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
          vbox->addWidget(edit);
          setLayout(vbox);
      }
      
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          // Embeded Edit:
          if (app.arguments().count() == 2) {
              EWidget window;
              QString windowId(app.arguments()[1]);
              window.embedInto(windowId.toULong());
              window.show();
              return app.exec();
      
              // Regular Edit:
          } else {
              Widget window;
              window.show();
              return app.exec();
          }
      }
      

      Build this executable, and remember its path, you will need to pass this path as an argument to the container application:

      #include <QtGui>
      #include <QX11EmbedContainer>
      
      int main(int argc, char **argv)
      {
      QApplication app(argc, argv);
      
      if (app.arguments().count() != 2) {
      qFatal("Error - expected executable path as argument");
      return 1;
      }
      
      QX11EmbedContainer container;
      container.show();
      
      QProcess process(&container);
      QString executable(app.arguments()[1]);
      QStringList arguments;
      arguments << QString::number(container.winId());
      process.start(executable, arguments);
      
      int status = app.exec();
      process.close();
      return status;
      }
      
      

      Now if you run the second executable with the path of the first executable as its argument, you will get a window with a QTextEdit that will give you focus issues.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            janichol Andy Nichols
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes