Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ShowMin/ShowMax window not working



  • I am trying to show the widgets minimized and maximized states using timer,
    The window is getting minimized but not maximized.

    after minimizing if i click on the task bar its showing in maximized state , but i want it show by itslef instead of a click.

    please help..

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "widget.h"
    Widget *objWidget_ptr;

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    objWidget_ptr = &w;
    w.show();

    return a.exec&#40;&#41;;
    

    }

    @

    widget.cpp
    @
    #include "widget.h"
    #include <QTimer>
    #include <QDebug>

    int min = 0;
    extern Widget *objWidget_ptr;
    Widget::Widget(QWidget *parent)
    : QWidget(parent)
    {
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    qDebug()<<"timer started ";
    timer->start(4000);
    }

    void Widget::update()
    {
    qDebug()<<"4 sec expipred ";

        if(!min) {
                objWidget_ptr->showMinimized();
                min =1;
                qDebug()<<"showing window in  minimized state";
        }else {
                //objWidget_ptr->resize(500,500);
                 objWidget_ptr->showMaximized();
                min =0;
                qDebug()<<"showing window in  maximized state";
        }
    

    }

    Widget::~Widget()
    {

    }

    @

    widget.h

    @
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QtGui/QWidget>

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    Widget(QWidget *parent = 0);
    ~Widget();
    public slots:
    void update();
    };

    #endif // WIDGET_H

    @



  • What version of Qt are you using ?
    I just ran this code with Qt 5.2 on Win7 with MSVC2010 and it behaved as expected.



  • I am running on Linux using Qt 5.0.

    my intention is to show some external video after minimizing the Qt UI, as an example i tried this.

    window is getting maximized, but it is not shown , only when i click on the icon its showing.

    do we need to generate any events for showing ..



  • Ok. I can duplicate your problem on ubuntu 13.04 with Qt 5.1.
    The work around is to call activateWindow() after the call to showMaximized().


Log in to reply