单击按钮,出现QPixmap,单击相同的按钮,QPIxmap消失

问题描述 投票:0回答:1

我试图能够点击一个按钮并有一个我正在使用弹出的Pixmap图像,当我再次单击该按钮时,它会消失。现在,当我运行我的应用程序时,图像已经存在,当我单击按钮时,它会消失。怎么修??

#include "yes.h"
#include "ui_yes.h"

yes::yes(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::yes)
{
    ui->setupUi(this);
}

yes::~yes()
{
    delete ui;
}

void yes::on_pushButton_clicked()
{
    hide();
}

void yes::on_pushButton_2_clicked()
{
    QPixmap popup("qrc:/new/prefix1/Popover for seat help");
    ui->label->setPixmap(popup);
}

看着on_pushButton_clicked()

qt
1个回答
0
投票

我想到了。只需使弹出窗口不可见,然后将可见性设置为与按钮单击时相反的可见性。

#include "yes.h"
#include "ui_yes.h"

yes::yes(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::yes)
{
    ui->setupUi(this);

    ui->label->setVisible(false);
}

yes::~yes()
{
    delete ui;
}

void yes::on_pushButton_clicked()
{
    hide();
}

void yes::on_pushButton_2_clicked()
{
    QPixmap popup("qrc:/new/prefix1/Popover for seat help");
   // ui->label->setPixmap(popup);
    ui->label->setVisible(!ui->label->isVisible());
}
© www.soinside.com 2019 - 2024. All rights reserved.