Qt World Summit: Submit your Presentation

Method raise() of class QWidget does not work as expected

  • I have a Mandriva2010 with kde4. I need to pick up an application window from a minimized state when it is restarted and new not open. I used to 2 methods -- raise() and activateWindow(). However, the window does not expand. Is it possible that this is some sort of incompatibility with KDE or do I need to use these methods as a way.
    Tell me please what is the problem here.

  • If the window is not expanding as you wished, i think , you may try with setting the maximum size. ex:

    @setMaximumSize(QSize(32767, 32767))@

  • Rahul, set the window size is not a good idea, I would like to return the window in the same condition in which it was.

  • Did you try "QWidget::showNormal":http://doc.qt.nokia.com/4.7/qwidget.html#showNormal ?

  • in the docs
    " On X11, the result depends on the Window Manager "
    " Note that the window must be visible, otherwise activateWindow() has no effect. "

  • Gerolf, yes, i'm try it :)

  • Rahul, i now that result depends on the Window Manager, so I wanted to know about the raise () for kde4. Because, this metod should perform the necessary role of I.

  • raise() brings the window to the top but does not change the size. So if you have a window that is in maximze or normal state and call raise(), it could come to front, but if it is minimized, it will not.

  • Gerolf, you are right, but this method ( raise() ) does not work as written in the documentation. This is not come window to front.

  • If the window comes to the front (if it is not minimized) is depending on the OS. On windows for example, raise does not work if your process does not own the input focus. This is done by MS win to ensure, not all windows can raise themselfe in front. Same applies to the input focus (activate).

  • Gerolf, we assume that raise() does not work, then you might know how to activate a window in another way? I'm doing now:

    In this case, the minimized window turns and rises above all other windows, but the focus on him is not translated. However, if the window is inactive and is behind other windows, then neither it nor the focus is not transferred to the top.
    Do you know something about this?

  • Gerolf, my question relates only to KDE and Mandriva Linux

  • I have seen that you are talking on linux, but I assume that in case of focus handling etc, they are not too much different.

    Calling activateWindow() (on windows I know) will also not get the focus, if the input focus is on a different application. This is against the windows policies, don't know exactly how it is on Linux X11. As stated in the docs, it depends on the window manager, so you can't rely on it to get the input focus (as you don't know which window manager your users will use).

    bq. raise():
    Raises this widget to the top of the parent widget's stack.
    After this call the widget will be visually in front of any overlapping sibling widgets.

    bq. activateWindow():
    This function performs the same operation as clicking the mouse on the title bar of a top-level window. On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well you should also call raise(). Note that the window must be visible, otherwise activateWindow() has no effect.
    On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window. It will change the color of the taskbar entry to indicate that the window has changed in some way. This is because Microsoft does not allow an application to interrupt what the user is currently doing in another application.

    IMHO forcing an application to give the focus to anotherone is not a good style. Those are things I hat on applications.

  • Gerolf, Thank you for such a detailed response. But it is necessary for me.
    Ok, May I offer you friendship? ^^

  • [quote author="Ruu_Rinki" date="1315400091"]Gerolf, Thank you for such a detailed response. But it is necessary for me.[/quote]

    We had the same problems in our project (but on windows) ;-) We have a singleton application which should üpop up if someone starts a second instance...

    What we did is, we forced our window to the top (set top level falg, remove it, via windows API), the only thing that does not work is setting the focus .... Not nice but better than nothing ...

Log in to reply