| 
UID:14911
注册时间2007-02-03最后登录2017-11-17在线时间82小时
发帖154搜Ta的帖子精华0
金钱1560威望157贡献值0好评度156
访问TA的空间加好友用道具
     | 
 
我新建了个GUI工程,父类设为QDialog,想模仿CCPorxy那样的界面:当最小化按钮被点击时把主界面自动隐藏起来。 思路:响应QEvent::WindowStateChange事件,如果是最小化就hide()它。但是都快一天了,这么一个简单的问题,无果。 NND,实在不行就得:winEvent()了。 代码如下: void Dialog::changeEvent(QEvent *e){    QDialog::changeEvent(e);    switch (e->type())    {    case QEvent::WindowStateChange:        if((this->windowState() & Qt::WindowMinimized) == Qt::WindowMinimized)        {            QMessageBox::about(this,QString::fromLocal8Bit("测试,2010-04-07"), QString::fromLocal8Bit("最小化时隐藏窗体。"));            //this->accept();   //程序自己退出            //e->accept();            //QHideEvent he;            //qApp->postEvent(this, &he, Qt::NormalEventPriority);            //qApp->postEvent(this, new QHideEvent, Qt::NormalEventPriority);            //--------------------------------------------------------            // 当QDialog::changeEvent(e);在本函数最前时            // 以下一条语句的2种组合            // 00, not work            // 01, not work            this->hide();       // 0            //QDialog::hide();  // 1            if (this->isHidden())// “已经隐藏”的对话框弹出,确定后程序退出,但是如果注释掉这两句,在第二次最小化时退出                QMessageBox::about(this,QString::fromLocal8Bit("测试,2010-04-07"), QString::fromLocal8Bit("已经隐藏窗体。"));            //--------------------------------------------------------            // 当QDialog::changeEvent(e);在本函数最前时            // 以下两条语句的4种组合            // 00, not work            // 01, not work            // 10, not work            // 11, not work            //this->hide();       // 0            //QDialog::hide();  // 1            //e->accept();        // 0            //e->ignore();      // 1            //--------------------------------------------------------            // 当QDialog::changeEvent(e);在本函数最后时            // 以下两条语句的4种组合            // 00, not work            // 01, not work            // 10, not work            // 11, not work            //this->hide();       // 0            //QDialog::hide();  // 1            //return;             // 1:use, 0:not use            //--------------------------------------------------------            // 当QDialog::changeEvent(e);在本函数最后时            // 以下三条语句的8种组合            // 000, not work            // 001, not work            // 010, not work            // 011, not work            // 100, not work            // 101, not work            // 110, not work            // 111, not work            //this->hide();       // 0            //QDialog::hide();  // 1            //e->accept();        // 0            //e->ignore();      // 1            //return;             // 1:use, 0:not use        }        break;    case QEvent::Hide:        QMessageBox::about(this,QString::fromLocal8Bit("测试,2010-04-07"), QString::fromLocal8Bit("窗体被隐藏。"));        break;    case QEvent::HideToParent:        QMessageBox::about(this,QString::fromLocal8Bit("测试,2010-04-07"), QString::fromLocal8Bit("窗体被隐藏到上层。"));        break;    case QEvent::LanguageChange:        ui->retranslateUi(this);        break;    default:        break;    }    //QDialog::changeEvent(e);}
 |