How to use .hide on a Qt LineEdit, still take input? - c++

I have a QLineEdit which I would like to hide from the user but still take in input form somewhere. I am creating a typing tutor and I want to take input in a hidden manner in order to provide a more dynamic form of feedback.
Any other suggestions as to best accomplish would be greatly appreciated

You can not do it. When QLineEdit is hidden, there is no focus on it, and you can not grab events.
If you persist on using QLineEdit there's an option to turn off displaying text.QLineEdit::NoEcho.
lineEdit->setEchoMode(QLineEdit::NoEcho);
This will show the edit box, but it doesn't show any text.
Otherwise, you should write a slot to grab window keyPressed signals, and handle everything yourself.

For other people who try to do such a thing, a workaround is simply to implement a QLineEdit visible, but with a MinimumSize = MaximumSize = 0x0 :)

Related

QComboBox::showPopup() steals focus from its QLineEdit

In order to create a QComboBox that can filter its values list when typing in it, I attached a slot to the QComboBox's editTextChanged-event, to open its list view popup when the user starts typing. This is done like so:
void SearchableComboBox::slotEditing(QString in_text)
{
this->showPopup();
}
Unfortunately, this immediatly steals the focus from the QLineEdit and I can't type anymore.
Calling lineEdit()->setFocus() makes no difference, and I don't want to grabKeyboard() since this creates a whole other world of pain.
Any recommendations?
This isn't really a combobox then, more of a completion listview for a lineedit. I implemented exactly that in ruqola (KDE client for rocket chat), you can see the source code at https://lxr.kde.org/source/network/ruqola/src/widgets/common/completionlistview.cpp. Notice the little dance with the focus proxy thing:
setFocusPolicy(Qt::NoFocus);
textWidget->setFocusPolicy(origPolicy);
setFocusProxy(textWidget);
and the long method slotCompletionAvailable() for positioning the completion popup at the right place...
Use the Focus Proxy method for this purpose. See https://doc.qt.io/qt-5/qwidget.html#setFocusProxy
With this the pop-up would relay its inputs to the lineedit.
In your case you could try something like
this->setFocusProxy( this->lineEdit() );
But maybe you should read how to use a QCompleter. This would provide Autocompletion while typing and is maybe also useful for you.

Hide vtkOutputWindow

How can I hide vtkOutputWindow? No suppress by
GlobalWarningDisplayOff() or redirect output to file but only
hide. (And show again after some time via something like vtkOutputWindow::GetInstance()->DisplayText(" ")). Thanks.
PS. I use Qt gui on Windows.
PPS. For those who are interested in this question I bring here mailing list correspondence (hiperlink not yet available):
Bel,Ok! Now I see what you meant. As you said, probably the easiest way to do that would be sending a close signal to the window.
As you can see on vtkWin32OutputWindow reference (https://www.vtk.org/doc/nightly/html/classvtkWin32OutputWindow.html) it is "a read only EDIT control", so if you could get its handle maybe you would be able to incorporate it to a window that you have control of.
Another, more complex, solution would be to create a new class that would inherit from vtkOutputWindow, based on vtkWin32OutputWindow but with controls to hide and show the control.
Best regards, Lucas Frucht Desenvolvimento
Lucas, thanks for reply. I don't need to "save changes" while vtkOutputWindow is hidden. In generally my question is about how to hide/show this window from gui in runtime. vtkOutputWindow class is not derived from any widget so it havn't any method like "hide" or "close". Also destroy it not help too.
vtkOutputWindow *w = vtkOutputWindow::GetInstance();
w->Delete();
... (redirecting...)
don't close it. It seem to sending close signal to window is the simplest solution.
Sincerely, Bel.
08.08.2018 18:04, lucas.frucht#medilabsistemas.com.br:
>
Bel,
There is one point that is not clear to me in your question. Do you want the messages that would have been shown when vtkOutputWindow is hidden to be discarded or to be shown when you unhide it?
If you want it to be discarded, I suppose you could redirect it to /dev/null on Unix or to nul on Windows and delete the redirection when you want to unhide the window.
If you just want to delay the output, maybe, you could redirect the messages to an vtkStringOutputWindow to store the messages on a string and when you want to show then, delete the redirection and call DisplayText passing the string where you stored the messages. I never tried this, but it seems reasonable to me.
Best regards, Lucas Frucht.
On Windows, this will maybe work (I haven't tested it though).
vtkSmartPointer<vtkWin32OutputWindow> outputWindow = vtkSmartPointer<vtkWin32OutputWindow>::New();
outputWindow->SetSendToStdErr(true);
vtkOutputWindow::SetInstance(outputWindow);
The output messages will be directed to stderr instead of the output window. To turn it on again, disable the redirection. Other possibilities include subclassing of vtkOutputWindow or to install an observer for error events that do what you need.
A similar question was posted here.

How do I detect the change in text without changing the focus in QPlainTextEdit Class?

With this Qt construct,
http://doc.qt.io/qt-4.8/qplaintextedit.html
I have tabChangesFocus
but what if I want to detect a change on the input without having to tab to detect it? I want to change and then be able to hit save, no tabbing or focus changing necessary.
You can use the textChanged() signal to do this.
This is a piece of code you can slightly modify to fit the requirements.
connect(ui->textBox, SIGNAL(textChanged()), this, SLOT(DoSmth()));

Qt QMainWindow central widget deletion

my application requires the user to switch between several screens. The way I'm doing this is by creating different QFrames for each screen, and then setting the Qframes as central widgets on the MainWindow. The problem is that every time I call setCentralWidget(frame), the old frame gets deleted and I can't access it later. How can save that old frame so that I can access it later?
Please let me know if I am unclear in my question.
You can remove your central widget from QMainWidow reparenting it. Then, you could set new centralWidget;
QWidget* savedWidget = mainWnd->centralWidget();
savedWidget->setParent(0);//now it is saved
mainWnd->setCentralWidget(newWidget);
Also using QStackedWidget possibly would be better solution.
QStackedWidget is an elegant solution for this problem, you can find out how to use it properly here.
You can play around with .hide()/.show() on the appropriate subwidgets to accomplish this. But a better solution for your case is almost certainly to use a QTabWidget or QStackedWidget.

Qt -how to know whether content in child widgets has been changed?

In QMainWindow I have 2 QSplitters. In that splitters I have QTextEdit, QLineEdits, QTableWinget, Ragio buttons and so on... I want to know if somthing has been chaged after pressing File->New menu button. Is there any general method for doing this?
Somwhere I have read that it is recomended to use isWindowModified() function of QMainWindow, but seems it doesn't work.
setWindowModified() does not propagate the windowModified flag to the parents. This bug is described here: https://bugreports.qt.io/browse/QTBUG-20150. I have just tried it and indeed it did not work.
The isWindowModified() could be useful here since according to http://doc.trolltech.com/4.6/qwidget.html#windowModified-prop it propagates up to the parent.
However, I think you would need to set this yourself. For example, if you clicked the new button which leads to some text being inserted into a QTextEdit, you still need to call QTextEdit's setWindowModified() function - which will then propagate up to your QMainWindow - and you can just check QMainWindow afterwards. (However, you wouldn't know which children were modified)
Maybe you should have a look at QWidget::changeEvent.