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

QGraphicsWidget does not respect focusPolicy

    XMLWordPrintable

Details

    • 310068

    Description

      Widgets that are added to a QGraphicsScene via QGraphicsProxyWidget do not obey the QWidget's or QGraphicsProxyWidget's focus policy.

      For example, having a QCheckBox with Qt::NoFocus policy will take the focus away from a QLineEdit.

      This only appears to occur for widgets on canvas.

      Non QGraphicsView widgets do obey the focusPolicy as expected.

      Update: The fix was reverted before 4.4.1 was released - this task has been reopened. The original fix was wrong.

      Test case main.cpp to reproduce issue
      ======================================
      #include <QtGui>

      class MainWindow : public QMainWindow
      {
      Q_OBJECT
      public:
      MainWindow(QWidget *parent = 0)
      : QMainWindow(parent)

      { QWidget *w = new QWidget(this); setCentralWidget(w); QVBoxLayout *layout = new QVBoxLayout(w); #if 0 // Non Widget on Canvas approach QCheckBox *cb = new QCheckBox("Check Box"); cb->setFocusPolicy(Qt::NoFocus); layout->addWidget(cb); layout->addWidget(new QLineEdit); #else // Widget on Canvas approach QGraphicsScene *scene = new QGraphicsScene; QGraphicsWidget *gw = new QGraphicsWidget; scene->addItem(gw); QGraphicsLinearLayout *gwLayout = new QGraphicsLinearLayout(Qt::Vertical, gw); QCheckBox *cb = new QCheckBox("Check Box"); cb->setFocusPolicy(Qt::NoFocus); QGraphicsProxyWidget *cbProxyWidget = new QGraphicsProxyWidget; cbProxyWidget->setFocusPolicy(Qt::NoFocus); cbProxyWidget->setWidget(cb); gwLayout->addItem(cbProxyWidget); QGraphicsProxyWidget *leProxyWidget = new QGraphicsProxyWidget; leProxyWidget->setWidget(new QLineEdit); gwLayout->addItem(leProxyWidget); QGraphicsView *view = new QGraphicsView(scene); layout->addWidget(view); #endif }

      };

      int main(int argc, char **argv)
      {
      QApplication a(argc, argv);
      MainWindow mw;
      mw.show();
      return a.exec();
      }

      #include "main.moc"

      Attachments

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

        Activity

          People

            hanssen Andreas Aardal Hanssen (closed Nokia identity) (Inactive)
            gpf Shane McLaughlin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes