[solved] minimize event



  • [Solved]
    hi i wrote a program i want to hide and sent it to tray when its minimized i used code below
    @bool myclass::event(QEvent *event)
    {
    if (event->type()==QEvent::WindowStateChange && isMinimized())
    {
    hide();
    event->ignore();
    }
    else{
    return QMainWindow::event(event);}
    }@
    but this happens
    before minimize
    !http://dl.2rialy.ir/ZiDoM-Ups/91/before.JPG(before)!
    after minimize
    !http://dl.2rialy.ir/ZiDoM-Ups/91/after.JPG(after)!

    i dont know why this happens because when i use this code
    @
    void myclass::closeEvent(QCloseEvent *event)
    {
    hide();
    event->ignore();
    }
    @
    it works fine



  • What happens when you let the event propagate to the mainwindow in both cases? (I.e. remove the event->ignore(); and the else branch)



  • no difference it same as now i test that before



  • Well, if you minimize a window it is automatically hidden (that's why you minimize it in the first place).

    If you are talking about hiding the taskbar entry see "this":http://qt-project.org/forums/viewthread/8902 thread.



  • those dont work to



  • How much use do you think can we make of "those dont work to"?



  • sorry but i thought its obvious i meant that the link that you suggest the codes in that link didn't work
    sorry because of bad explaining



  • So, what have you tried? How does the code look like? What did you expect? And what is it actually doing?



  • I tried this
    @
    int main(int argc, char *argv[])
    {
    QApplication application(argc, argv);

    QWidget widget;
    QMainWindow mainWindow(&widget);
    
    mainWindow.show();
    
    return application.exec();
    

    }
    @
    but it doesn't hide the taskbar icon hides the window to
    and when i tried this
    @int main(int argc, char *argv[])
    {
    QApplication application(argc, argv);

    QMainWindow mainWindow;
    
    mainWindow.show();
    
    ShowWindow(mainWindow.winId(), SW_HIDE);
    SetWindowLong(mainWindow.winId(), GWL_EXSTYLE, GetWindowLong(mainWindow.winId(), GWL_EXSTYLE) | ~WS_EX_APPWINDOW);
    ShowWindow(mainWindow.winId(), SW_SHOW);
    
    return application.exec();
    

    }@
    i received some errors



  • Snippet #1 does not show a taskbar icon, and so does setting the Qt::Tool window flag - at least for me.
    @
    void MainWindow::changeEvent(QEvent *event)
    {
    if (event->type() == QEvent::WindowStateChange)
    {
    if (isMinimized() == true)
    setWindowFlags(windowFlags() | Qt::Tool);
    else
    setWindowFlags(windowFlags() & ~Qt::Tool);
    }

    return QMainWindow::changeEvent(event);
    

    }@

    Using ~WS_EX_APPWINDOW does, as mentioned in the linked thread, not work properly.



  • [quote author="zidom" date="1348914755"]hi i wrote a program i want to hide and sent it to tray when its minimized i used code below
    @bool myclass::event(QEvent *event)
    {
    if (event->type()==QEvent::WindowStateChange && isMinimized())
    {
    hide();
    event->ignore();
    }
    else{
    return QMainWindow::event(event);}
    }@
    [/quote]

    hi

    @if (event->type()==QEvent::WindowStateChange && isMinimized())
    {
    hide();
    show();
    hide();
    event->ignore();
    }
    else{
    return QMainWindow::event(event);}@



  • Hi mahdi
    Thanks that worked but i don't understand why i should hide then show then hide again
    im iranian like you :D



  • bq.

     void MainWindow::changeEvent(QEvent *event)
    {
        if (event->type() == QEvent::WindowStateChange)
        {
            if (isMinimized() == true)
                setWindowFlags(windowFlags() | Qt::Tool);
            else
                setWindowFlags(windowFlags() & ~Qt::Tool);
        }
     
        return QMainWindow::changeEvent(event);
    }
    

    I used that it works for hiding but when i want to show the form again

    void myclass::trayicon_click(QSystemTrayIcon::ActivationReason reason)
    {
        if(reason==QSystemTrayIcon::Trigger)
        {
            show();
        }
    }
    

    it looks like this when i show the form !http://dl.2rialy.ir/ZiDoM-Ups/91/after.JPG(show)!



  • This example may help you:
    http://doc.qt.digia.com/4.7-snapshot/desktop-systray.html
    (void Window::closeEvent(QCloseEvent *event))



  • Use showNormal() instead.



  • bq. This example may help you:
    http://doc.qt.digia.com/4.7-snapshot/desktop-systray.html
    (void Window::closeEvent(QCloseEvent *event))

    I already saw that but that doesn't help me by the way thank

    bq. Use showNormal() instead.

    thanks a lot that worked again thanks for following this article and helping me



  • You're welcome.

    Feel free to prepend the thread title with [Solved] (just edit your initial post) to indicate that there is a solution inside.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.