How to change focus between TextEdit boxes using tab key - c++

I have 2 TextEdit boxes and 5 buttons that are arranged in linear order.
The focus should be on the first TextEdit box when the program is started.
When tab key is pressed it should change the focus to the next widget.
Actually when a tab key is pressed the tab space is entered inside the TextEdit box. instead of moving to the next box. I also cannot use LineEdit Box because the input needs to be displayed in multiple lines. anyway the input wont contain enter key or '\n'

To change the behaviour of tab key you should look here:
http://doc.qt.io/qt-5/qplaintextedit.html#tabChangesFocus-prop
bool tabChangesFocus() const
void setTabChangesFocus(bool b)

Related

How to detect an enter key press inside edit box in Win32 API c++ [duplicate]

Win32/C++. I have a multiline edit control and a pushbutton that I've made default with DM_SETDEFID. When I hit enter with focus on the edit, I want the focus to stay there instead of moving to the pushbutton.
The edit control should have ES_WANTRETURN style to change behavior to desired:
Specifies that a carriage return be inserted when the user presses the
ENTER key while entering text into a multiline edit control in a
dialog box. If you do not specify this style, pressing the ENTER key
has the same effect as pressing the dialog box's default push button.
This style has no effect on a single-line edit control.
To change this style after the control has been created, use
SetWindowLong.

Qt: How to shift the cursor focus to a field in a Find dialog box/tool once it's shown?

I'm working on a text editor project, and the Find tool currently looks like this when launched:
I'm wondering how I could shift the application/text cursor focus so it goes within the "Find what" field automatically as soon as I show the dialog box (which is of type QDialog).
Currently, as you can see, the text cursor remains within the document, so the user has to manually click on the Find tool to start searching, which is a bit iconvenient. I tried messing around with the setFocus method of my dialog box, but that doesn't seem to help.
To activate the focus in the QDialog do the following:
void MainWindow::on_actionFind_triggered()
{
if(findDialog->isHidden())
{
findDialog->show();
findDialog->activateWindow();
findDialog->raise();
findDialog->setFocus();
}
}
But by default the one that will take the focus will be the QPushButton, so to change that behavior it must be established as a QDialog proxy to the QLineEdit.
lineEdit = new QLineEdit();
setFocusProxy(lineEdit); // <---

Win32 Enter while in textbox triggers ok button

The title isn't very explicit but here is my problem :
I have a MFC-based application with a dialog that has :
1 Text input;
1 Ok button;
1 cancel button;
1 button with an arrow to type in the next value
When the text box has the focus, pushing enter triggers the OK button. Why ? The text box has the focus, not the OK button so why would it do that ?
What i need ito to redirect the enter key to the arrow button instead of the ok button so that pushing enter doesn't close the dialog but goes to the next input.
Why can i do that please ? If i use SetFocus on the arrow button, the text box loses the focus, as expected, and this is not what i want.
You must set the Multiline and the Want Return properties of your edit control to True.
If an edit control does not have the style ES_WANTRETURN pressing ENTER has the same effect as pushing the dialog's default button. However, this style has no effect on single line controls, so you must also set the ES_MULTILINE style for the control.

Sending text from QTextEdit to QListWidget on pushing QPushButton - Qt

So, I have the following design:
List box
Text box
Push button
When I push the button, the text from the text box should go to the list box.
QTextEdit has the following signal:
void QTextEdit::textChanged () [signal]
But, doesn't this mean that when user presses an alphabet, a signal will be sent? But, I want the whole paragraph to go to the list box (at once) on the push of the button.
Should I send the data from text box to button and then from button to list box? Or there another way out?
EDIT 1:
I have been successful in sending the text from list box to the button, but how to send the text from button to list box?
Button has no signal which sends the text.
you should handle QPushButtons's clicked signal and then in that signal you can get QTextEdit's text content by toPlainText () API and you can insert this to List box's model

Entering data into a Qt GUI with the keyboard: unintended side effects when pressing enter

I've written a Qt GUI which contains some QSpinBoxes and QDoubleSpinBoxes, among other stuff. Everything works as intended, except for one thing: when I enter a number into the QSpinBoxes and finish the entry by pressing the "Enter" key, this also activates the first widget in the tab order: i.e. instead of just changing the value of my spin box, I'm also pressing the button at the top of my dialog - which I don't want. How can I fix this? (Note that I need to press Enter for the new value to be accepted, because the spin boxes' keyboard tracking is deactivated.)
EDIT: In case someone comes across a similar problem: http://developer.qt.nokia.com/doc/qt-4.8/eventsandfilters.html
I think what might be happening is the default button of a QDialog is being pressed when you press Enter.
If you are subclassing QDialog yourself, then one of your QPushButtons has it's default property set to true. If you revert that to false, then the button will not react to the Enter key unless in focus. The disadvantage here, is that your dialog can't be dismissed by pressing Enter, if you want to stick with the default values for example.