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

QLineEdit read-only switch

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.4.2
    • None
    • Windows 7, Windows 8
      Ubuntu 12.04

    Description

      Problem when you switch a QLineEdit read-only true/false the text cursor is not visible until one key input.
      Here a minimal code who reproduce the issue and can be compiled easy.
      The code contains a QVBoxLayout to switch because when the CustomLineEdit lost focus he changes his state.
      By default the CustomLineEdit is on read-only and waits a double click to change value.

      #include <QApplication>
      #include <QMainWindow>
      #include <QLineEdit>
      #include <QVBoxLayout>
       
      class CustomLineEdit : public QLineEdit
      {
          Q_OBJECT
      public:
       
          CustomLineEdit(QWidget* parent = 0) :
          QLineEdit(parent)
          {
              setReadOnly(true);
              setText("0.00");
          }
       
      protected:
       
          virtual void focusOutEvent(QFocusEvent* event)
          {
              QLineEdit::focusOutEvent(event);
              setReadOnly(true);
              deselect();
          }
       
          virtual void mouseDoubleClickEvent(QMouseEvent* event)
          {
              if(isReadOnly())
                  setReadOnly(false);
              else
                  QLineEdit::mouseDoubleClickEvent(event);
          }
      };
       
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      public:
       
          MainWindow(QWidget* parent = 0) :
          QMainWindow(parent)
          {
              QVBoxLayout* Layout = new QVBoxLayout;
              Layout->addWidget(new QLineEdit);
              Layout->addWidget(new CustomLineEdit);
              QWidget* Widget = new QWidget(this);
              Widget->setLayout(Layout);
              setCentralWidget(Widget);
          }
      };
       
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            peppe Giuseppe D'Angelo
            alundra Michael Ségura
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes