简体   繁体   中英

Display Dicom image in QLabel/QGraphicsView

I'm new to MITK and not an advanced programmer. I need help displaying a DICOM image in a QT Widget. I am using Visual Studio 2013, MITK, and QT5 to develop a program, that is supposed to open and view DICOM images. The user browses an image which is then displayed. I`ve seen here: Interactively editing an existing rectangle on a QPixmap? that it is possible with a QLabel and QGraphicsview. I just don't know how to use that in my program:

void MainWindow::on_openButton_pressed()
{
QString imagePath = QFileDialog::getOpenFileName(
    this, tr("Open File"),
    "",
    tr("JPEG(*.jpg *.jpeg);;DICOM(*.dcm)")
    );
imageObject = new QImage();
imageObject->load(imagePath); //bool status is false here
image = QPixmap::fromImage(*imageObject)
image.load(imagePath);

QSize bigsize = ui->bigImageLabel->size();
QSize bigsize = ui->label->size();
ui->label->setPixmap(image.scaled(bigsize, Qt::IgnoreAspectRatio, Qt::FastTransformation));
ui->label->show();
}

I also tried using QGraphicsView (which only works for JPEGs).

scene = new QGraphicsScene(this);
scene->addPixmap(image);
scene->setSceneRect(image.rect());
ui->ViewCoronal->setScene(scene);

I hope someone can help me. Thanks in advance

If QImage::load failed there is no point to convert it QPixmap, because of QImage by default constructed with size 0,0 and you see nothing when you show such QPixmap. By default Qt not support "DICOM" image format, so you cann't show this image using any part of Qt functionality.

So you can implement Qt plugin for this image format by your self, see http://doc.qt.io/qt-5/qtimageformats-index.html or take existing one, mitk have one according to http://docs.mitk.org/2015.05/group__org__mitk__gui__qt__dicom.html#details

But to use mitk plugin you should place into right place, like path/to/qt5/plugins/imageformats also you have to make sure that your program, Qt and MITK using the same configuration like Debug/Release

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM