压缩和释放时位图图像如何变化?

时间:2017-09-26 15:26:44

标签: c++ qt bitmap

这是使用Qt 4在按下并释放QPushButton时更改图像位图的代码:

void MainWindow::on_pushButton_2_pressed()
{
    QString filename = QFileDialog::getOpenFileName(this, tr("Choose"), "", tr("images (*.bmp)"));

    if(QString::compare(filename, QString()) != 0)
    {
        QImage image;
        bool volid = image.load(filename);

        if(volid)
        {
            ui->lineEdit->setText(filename);

            QPixmap pixmap (filename);
            QIcon ButtonIcon (pixmap);
            ui->pushButton->setIcon(ButtonIcon);
            ui->pushButton->setAutoRepeat(true);
        }
        else
        {
            // Error handling
        }
    }
}

void MainWindow::on_pushButton_3_released()
{
    QString filename = QFileDialog::getOpenFileName(this, tr("Choose"), "", tr("images (*.bmp)"));

    if(QString::compare(filename, QString()) != 0)
    {
        QImage image;
        bool volid = image.load(filename);

        if(volid)
        {
            ui->lineEdit_2->setText(filename);

            QPixmap pixmap (filename);
            QIcon ButtonIcon (pixmap);
            ui->pushButton->setIcon(ButtonIcon);
            ui->pushButton->setAutoRepeat(false);
        }
        else
        {
            // Error handling
        }
    }
}

下图显示我需要选择两张图片并添加按钮操作,以便在按下和释放时更改。

enter image description here

0 个答案:

没有答案