PDA

View Full Version : Set focus to other control when clicking a QPushButton



marcvanriet
8th October 2010, 01:14
Hi,

I have a table (QTableView) in which a user can select a row. Then I have 2 buttons to change a field in this table to a fixed value. The first buttons sets the field to 'M', the other one to 'D'.

When the user presses one of the buttons with the mouse, the QTableview loses focus. I want the focus to stay on the QTableView. How could I do this ?

The reason is that I would like the user to be able to select a record using the cursor keys, press one of the buttons, and then continue to select a different record without first having to set the focus to the table.

I tried to use setFocus() of the QTableView widget in the clicked() event of my pushbuttons, and in the release() event, but this doesn't work.

Any suggestions ?

Best regards,
Marc

ChrisW67
8th October 2010, 03:49
QWidget::focusPolicy() on the push buttons perhaps. Disable focus by click.

Lykurg
8th October 2010, 07:03
set a strong focus for the view and Qt::NoFocus for the buttons (as policies).

Edit: Ehm, what's up with me? The answer was already given by ChrisW67. Sorry, just ignore my post.