QT實現窗口縮放打開與關閉(重疊窗口,太有意思了)


基本思想:假設A為主窗口,B為子窗口。A打開或關閉時,先對A窗口進行截圖,然后將圖片部滿整個B窗口的,在paintEvent里面進行動態縮放或放大畫圖。最后使用動畫,將B窗口以動畫的形式打開或關閉,動畫播放完畢后,B發送一個信號給A,B關閉,A顯示出來。

核心代碼發下:

在A窗口里:

QPixmap pixmap;

    CTestDialog dlg(this);
    dlg.SetPixmap(pixmap.grabWidget(this));
    hide();
    dlg.exec();

 

B窗口:

CTestDialog::CTestDialog(QWidget *pParent) : QDialog(pParent)
{
    ui.setupUi(this);
    setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); 
}

CTestDialog::~CTestDialog()
{
}

void CTestDialog::SetPixmap(const QPixmap &pixmap)
{
    m_backPixmap = pixmap;
    m_image = pixmap.toImage();
    update();

    QDesktopWidget *desktopWidget = QApplication::desktop();
    QRect screenRect = desktopWidget->screenGeometry();

    QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
    animation->setDuration(2200);
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->setStartValue(QRect((screenRect.width() - 50) / 2, (screenRect.height() - 50) / 2, 50, 50));
    animation->setEndValue(QRect((screenRect.width() - 500) / 2, (screenRect.height() - 400) / 2, 500, 400));
    animation->start();
}

void CTestDialog::paintEvent(QPaintEvent *p)
{
     QPalette pal(palette());
     pal.setBrush(QPalette::Window, QBrush(m_image.scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
     setPalette(pal);
}

 
http://blog.csdn.net/itjobtxq/article/details/9663757


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM