tags:

views:

3910

answers:

9

I'm a new in Qt Designer 4.4.1 Open Source Edition. I used to program in Windows Borland C++ Builder and I've switched to Linux.

I do not know how to gain the control when a widget (a LineEdit in the specific case) gains the focus, no mater if by tab or by clicking or by any other medium. My Focus Policy to the widget is "strongFocus", so it is enabled to receive.

In Borland Builder, each object has a table with all possible events. For Edit field there is among the events one called "OnEnter" who signalizes the focus entering that object (similarly there is "OnExit")

Qt has something similar?
Can someone help me. I'll be gratefull. Luis

A: 

There is a "focusChanged" signal sent when the focus changes.
It has two arguments, he widget losing focus and the one gaining focus.

Martin Beckett
+2  A: 

I'd have to play with it, but just looking at the QT Documentation, there is a "focusInEvent". This is an event handler.

Here's how you find information about.... Open up "QT Assistant". Go to the Index. Put in a "QLineEdit". There is a really useful link called "List of all members, including inherited members" on all the Widget pages. This list is great, because it even has the inherited stuff.

I did a quick search for "Focus" and found all the stuff related to focus for this Widget.

Bob
A: 

Dear Bob

Many thanks for your attention to my problem. Before putting the question I've done the reading yet, but I'tried to code, in the Form120's constructor like that:

" connect(lineEdit12,SIGNAL(focusInEvent(lineEdit12)), this, SLOT(myroutine(void)));"

g++ compiled well but during processing I received such messages:

Object::connect: No such signal QLineEdit::focusInEvent(lineEdit12)

Object::connect: (sender name: 'lineEdit12')

Object::connect: (receiver name: 'Form120')

please I ask your help. thanks Luis

This isn't a forum, reply as a comment.
Max Howell
A: 

QWidget::setFocus() is slot, not signal. You can check if QLineEdit is in focus with focus property. QLineEdit emits signals when text is changed or edited, see documentation.

+1  A: 

Qt Designer isn't designed for this level of WYSIWYG programming.

Do it in C++:

class LineEdit : public QLineEdit
{
    virtual void focusInEvent( QFocusEvent* )
    {}
};
Max Howell
+1  A: 

You have hit on of the weird splits in QT, if you look at the documentation focusInEvent is not a slot it is a protected function, you can override it if you are implementing a subclass of your widget. If you you just want to catch the event coming into your widget you can use QObject::installEventFilter it let's you catch any kind of events.

For some odd reason the developers of Trolltech decided to propagate UI events via two avenues, signals/slots and QEvent

Harald Scheirich
You can override a virtual base function. That is why events are virtual functions. Trolltech use signals instead when inheritance for that functionality is not likely to be useful.
Max Howell
A: 

The simplest way is to connect a slot to the QApplication::focusChanged signal.

+1  A: 

You can add en event filter.
This is an example of an application written with QtCreator. This form has a QComboBox named combobox.


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->comboBox->installEventFilter(this);
    .
    .
    .
}

bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() == QEvent::FocusOut)
    {
        if (object == ui->comboBox)
        {
            qWarning(object->objectName().toLatin1().data());
        }
    }
    return false;
}
Karl
+1 Exactly what I was looking for, thank you!
lostriebo
A: 

Karl you are The Man!

Rafik