How to set focus to the playing field after I have pushed buttons

This is a tetris.

In Qt Designer I added a new Mani Window. Then I added a frame widget on to the window and a couple of Push Buttons (New game and Pause). And promoted the frame to QtGlass class.

Then I organized classes:

class Field : public QMainWindow {
    Q_OBJECT
...

class QtGlass : public QFrame {
        Q_OBJECT    
    ...

After clicking the buttons I would like to immediately return the fous to my playing field, that is frame.

When I'm inside Field class, I can do this: widget.frame->setFocus();

But when I click a button I seem to be out of the Field class. I seem to be inside QtGlass as in the Signal/Slot editor I connected the events with QtGlass slots.

Could you help me with setting the focus?


QFrame doesn't accept focus by default. Add the following line to the constructor of QtGlass :

setFocusPolicy(Qt::StrongFocus);

Also names of your classes should not start with Q . See this question.

链接地址: http://www.djcxy.com/p/6688.html

上一篇: 在QWebView中设置文本输入焦点

下一篇: 按下按钮后如何将焦点设置到游戏区域