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

Blink timer for QLineEdit not killed after QMenu spawn

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.5.1, 5.6.0, 6.8
    • None
    • Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160224) on "xcb"
      OS: Debian GNU/Linux stretch/sid [linux version 4.4.0-1-amd64]
    • e35dcba5b (dev), 43362244a (6.7), 78a3917b6 (6.6), 2d0a953bd (tqtc/lts-6.5)

    Description

      If the QMenu with embedded QLineEdit is spawned from a window with Qt::WindowDoesNotAcceptFocus flag and the edit gets focus -> the internal QLineEdit's blink timer is not killed after the menu is hidden/closed. This in turn makes unneccessary wakup every half a second.

      In the following example, the (testing) style's pixelMetric is called endless once the menu was shown and the QLineEdit got focus (no matter if programaticaly with setFocus or by mouse click):

      ...
      Monday, March 21, 2016 6:22:08 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:09 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:09 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:10 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:10 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:11 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:11 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:12 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:12 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:13 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:13 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:14 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:14 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:15 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:15 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:16 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:16 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:17 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      Monday, March 21, 2016 6:22:17 PM CET QStyle::PixelMetric(PM_DefaultFrameWidth)
      ...
      

      Code:

      main.cpp
      #include <QApplication>
      #include "widget.h"
      
      int main(int argc, char * argv[])
      {
          QApplication app{argc, argv};
          Widget w;
          w.show();
      
          return app.exec();
      }
      
      widget.h
      #if !defined(WIDGET_H)
      #define WIDGET_H
      
      #include <QFrame>
      
      class QProxyStyle;
      
      class Widget : public QFrame
      {   
          Q_OBJECT
      public:
          Widget(QFrame * parent = 0, Qt::WindowFlags f = 0);
          ~Widget();
      
      private:
          QScopedPointer<QProxyStyle> mStyle;
      };
      
      #endif //WIDGET_H
      
      widget.cpp
      #include "widget.h"
      #include <QDebug>
      #include <QGridLayout>
      #include <QLineEdit>
      #include <QPushButton>
      #include <QProxyStyle>
      #include <QWidgetAction>
      #include <QMenu>
      #include <QDateTime>
          
      namespace
      {   
          class StyleHelper : public QProxyStyle
          {
          public:
              using QProxyStyle::QProxyStyle;
              virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const override
              {
                  qDebug().noquote() << QDateTime::currentDateTime().toString(Qt::SystemLocaleLongDate) << metric;
                  return QProxyStyle::pixelMetric(metric, option, widget);
              }
          };
      
      }
      
      Widget::Widget(QFrame * parent, Qt::WindowFlags f)
          : QFrame{parent, f | Qt::WindowDoesNotAcceptFocus}
          , mStyle{new StyleHelper}
      {
          setFixedSize({200, 200});
          QLineEdit * edit = new QLineEdit;
          edit->setStyle(mStyle.data());
      
          QWidgetAction * action = new QWidgetAction{this};
          action->setDefaultWidget(edit);
      
          QMenu * menu = new QMenu{this};
          menu->addAction(action);
      
          QPushButton * button = new QPushButton{QStringLiteral("show/hide")};
          connect(button, &QAbstractButton::clicked, [edit, menu]
              {
                  if (menu->isVisible())
                      menu->hide();
                  else
                  {
                      menu->popup(QCursor::pos());
                  }
              });
          
          QGridLayout * l = new QGridLayout;
          setLayout(l);
          l->addWidget(button, 0, 0);
      }
                  
      Widget::~Widget()
      {       
      }   
      

      Attachments

        For Gerrit Dashboard: QTBUG-52021
        # Subject Branch Project Status CR V

        Activity

          People

            liaqi Liang Qi
            palinek Palo Kisa
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes