Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Qt, How do I make a window be the current window?

Tags:

qt

qt4

My QT app has multiple windows and sometimes, even though the windows are already open but burried under other windows, the user will select an option to open one from the mainwindow menubar in which case I want to simply bring it up and make it the current one. Now using QWidget->raise makes this window go on top of all other windows but it doesnt select it and that is what I need to do. I tried QWidget->setFocus but that doesnt do anything. In the mean time I am using a combination of QWidget->close followed by QWidget->show but I would like to know if there is a command to use with ->raise.

I tried:

        pMission->raise();
        pMission->setFocus(Qt::ActiveWindowFocusReason);

but it didnt work so i used:

        pMission->close();
        pMission->show();
like image 382
yan bellavance Avatar asked Feb 10 '10 22:02

yan bellavance


2 Answers

Have you ever tried QWidget::activateWindow?

From help file, this function is going to

Sets the top-level widget containing this widget to be the active window. An active window is a visible top-level window that has the keyboard input focus.

like image 170
Mason Zhang Avatar answered Nov 20 '22 08:11

Mason Zhang


On MacOS Lion with Qt 4.8.0, raise() was the only one that worked for me. activateWindow() and setFocus() did not.

(I don't have enough karma to make this a comment on Mason's answer)

like image 43
prewett Avatar answered Nov 20 '22 08:11

prewett