QLineEdit no longer accepts input after dis- and reenable QMainWindow on Mac/4.8.5



  • Steps to reproduce:

    QLineEdit widget in QMainWindow

    window()->setEnabled(false); // disable whole window/menu for device communication, no abort

    window()->setEnabled(true); // enable it again

    QLineEdit no longer reacts to keyboard input

    I can reproduce this on Mac 10.8.5 with Qt 4.8.5. Works on Win/4.8.5

    Is this a bug or do I something wrong?
    What else than disabling the mainwindow would you suggest to prevent user input while communicating to a device? The user should not be able to do anything (quit, click widgets, select menu items,...). Switching apps, moving windows is ok.

    MainWindow.cpp
    @#include "MainWindow.hpp"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    mEdit = new QLineEdit("after clicking the button, you no longer can edit this text", this);
    mButton = new QPushButton("Disable window for 1 second", this);
    mTimer = new QTimer(this);

    QWidget *centralwidget = new QWidget(this);
    QVBoxLayout *layout = new QVBoxLayout(centralwidget);
    layout->addWidget(mEdit);
    layout->addWidget(mButton);

    setCentralWidget(centralwidget);
    resize(500, 70);

    connect(mButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
    connect(mTimer, SIGNAL(timeout()), this, SLOT(reenable()));
    }

    MainWindow::~MainWindow()
    {
    }

    void MainWindow::buttonClicked()
    {
    // disable whole window/menu for device communication, no abort
    window()->setEnabled(false);
    mTimer->start(1000); // reenable after a second
    }

    void MainWindow::reenable()
    {
    window()->setEnabled(true);
    }@

    MainWindow.hpp
    @#ifndef MAINWINDOW_HPP
    #define MAINWINDOW_HPP

    #include <QtGui>

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    QLineEdit *mEdit;
    QPushButton *mButton;
    QTimer *mTimer;

    public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public Q_SLOTS:
    void buttonClicked();
    void reenable();
    };

    #endif // MAINWINDOW_HPP@


  • Lifetime Qt Champion

    Hi,

    You might be experiencing the same problem described "here":http://qt-project.org/forums/viewthread/34090/

    You can try the patch attached to the bug report



  • Thank you. This one line patch solved the issue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.