Qt-interest Archive, May 2008
QTextEdit and focus?
Message 1 in thread
Hi
Some questions on QTextEdit and focus.
I have created widget with a QTextEdit and a QComboBox. From the ComboBox
the user can choose some variables for inserting in the TextEdit (at the
current cursor position).
Now if I click on the combobox cursor is reset to the first position. The
position and selection is gone.
I tried use popup->setFocusProxy( textEdit ) without luck.
How can I prevent this cursor resetting?
--
[ signature omitted ]
Message 2 in thread
On Wednesday 28 May 2008 09:48:22 Daniel Hüttenberger wrote:
> Hi
>
> Some questions on QTextEdit and focus.
> I have created widget with a QTextEdit and a QComboBox. From the ComboBox
> the user can choose some variables for inserting in the TextEdit (at the
> current cursor position).
> Now if I click on the combobox cursor is reset to the first position. The
> position and selection is gone.
> I tried use popup->setFocusProxy( textEdit ) without luck.
>
> How can I prevent this cursor resetting?
QTextEdit offers what you need. QLineEdit resets the textcursor on focus loss
and there is nothing you can do. forcing the focus to stay is not what you
want.
I'd just overload keyPressEvent of QTextEdit and filter return.
--
[ signature omitted ]
Message 3 in thread
Don't know if you understood me. Or I don't understand you.
Following code:
class Test : public QWidget
{
Q_OBJECT
public:
Test(QWidget *parent = 0);
private:
QTextEdit *edit;
QComboBox *combo;
private slots:
void insertFromCombo(int index);
};
Test::Test(QWidget *parent) : QWidget(parent)
{
edit = new QTextEdit;
combo = new QComboBox;
combo->addItem(tr("Test1"), "test1");
combo->addItem(tr("Test2"), "test2");
combo->addItem(tr("Test3"), "test3");
connect(combo, SIGNAL(activated(int)), this,
SLOT(insertFromCombo(int)));
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(combo);
layout->addWidget(edit);
}
Test::insertFromCombo(int index)
{
edit->insertPlainText( combo->itemData(index).toString() );
}
This is my plan.
"Arvid Ephraim Picciani" <aep@xxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:200805281024.32816.aep@xxxxxxxxxxxxxxxxxx
On Wednesday 28 May 2008 09:48:22 Daniel Hüttenberger wrote:
> Hi
>
> Some questions on QTextEdit and focus.
> I have created widget with a QTextEdit and a QComboBox. From the ComboBox
> the user can choose some variables for inserting in the TextEdit (at the
> current cursor position).
> Now if I click on the combobox cursor is reset to the first position. The
> position and selection is gone.
> I tried use popup->setFocusProxy( textEdit ) without luck.
>
> How can I prevent this cursor resetting?
QTextEdit offers what you need. QLineEdit resets the textcursor on focus
loss
and there is nothing you can do. forcing the focus to stay is not what you
want.
I'd just overload keyPressEvent of QTextEdit and filter return.
--
[ signature omitted ]
Message 4 in thread
This works the way I would expect it to work:
void Test::insertFromCombo(int index)
{
edit->insertPlainText( combo->itemData(index).toString() );
edit->setFocus(); // <--
}
Do you want it to behave somehow different?
--
[ signature omitted ]
Message 5 in thread
On Thursday 29 May 2008 15:15:51 J-P Nurmi wrote:
> This works the way I would expect it to work:
>
> void Test::insertFromCombo(int index)
> {
> edit->insertPlainText( combo->itemData(index).toString() );
> edit->setFocus(); // <--
> }
>
> Do you want it to behave somehow different?
well i guess he wants to move the input cursor after the last character so the
user can continue to write right away.
--
[ signature omitted ]