【问题标题】:I want to show image in new window as soon as image is clicked in mainwindow qt我想在主窗口 qt 中单击图像后立即在新窗口中显示图像
【发布时间】:2022-10-02 21:49:56
【问题描述】:

我想在新窗口中显示我的图像。所以我试图通过构造函数将图像的路径作为值传递

void DicomWidget::mouseDoubleClickEvent(QMouseEvent *event){
    qDebug() << ui->diWidget->whatsThis();
    QString path = ui->diWidget->whatsThis();
    EditWindow * editWindow = new EditWindow(this);
    editWindow->setWindowTitle(path);
    editWindow->setWhatsThis(path);
    editWindow->show();
}

我想在构造函数中传递路径,但如果我这样做,editwindow 的 UI 不会呈现

我的editwindow.cpp

#include \"editwindow.h\"
#include \"ui_editwindow.h\"

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

}

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

//Here i need to have refernce to this how shoul i give it
EditWindow::EditWindow(QString& filepath){
    QFile file (filepath);
    QFileInfo fileInfo(file.fileName());
    QString filename(fileInfo.fileName());
    QString name = filename;
    currentDicomPath = filepath;
}

void EditWindow::on_pushButton_clicked()
{
    currentDicomPath =  EditWindow::windowTitle();
    qDebug() <<\"Hello9\" << currentDicomPath;
}
  • 您真的将图像的路径存储在QWidget::whatsThis() 中吗?我怀疑是...
  • 我尝试通过构造函数,但我不能通过构造函数传递它,如果我这样做,新窗口不会呈现

标签: c++ qt qt5


【解决方案1】:

通过使用EditWindow::EditWindow(QString&amp; filepath) 重写构造函数,使用EditWindow::EditWindow(QWidget *parent) 的Qt 构造函数将不会运行,因此您看不到任何渲染。

考虑用EditWindow::EditWindow(QWidget *parent, QString&amp; filepath) 之类的东西修改现有的构造函数,并在ui-&gt;setup(this); 下面添加您的自定义代码

之后,您可以使用EditWindow* editWindow = new EditWindow(this, filepath); 开始您的课程

否则,您只是创建了现有构造函数的overload。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2014-10-30
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多