# vtkResliceCursorWidget compatibility with QT QVTKWidget

**URL:** https://discourse.vtk.org/t/vtkreslicecursorwidget-compatibility-with-qt-qvtkwidget/8562
**Category:** Development
**Created:** [May 24, 2022, 1:17am UTC](https://discourse.vtk.org/t/vtkreslicecursorwidget-compatibility-with-qt-qvtkwidget/8562 "2022-05-24T01:17:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Alexandera](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@Alexandera](https://discourse.vtk.org/u/Alexandera)
#### Post date: [May 24, 2022, 1:17am UTC](https://discourse.vtk.org/t/vtkreslicecursorwidget-compatibility-with-qt-qvtkwidget/8562/1 "2022-05-24T01:17:15Z")

</div>

Hi,

I am working on the medical GUI development with QT and VTK. I have made MPR (MultiPlanar reformation) in VTK alone, but it does not show when I show it in QT (basically I add the renderwindow and renderer to QVTKWidget). I also tried QVTKOpenGLNativeWidget as an option, but it does not work as well. I knew it needs vtkGenericOpenGLRenderWindow where for display.

###coding environment:  
QT5.9 VS2017 VTK8.2.0

Could you share you experience with QT+VTK…thanks!

###alone:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/10eeca76bbceb48fbf4561456e5eaa2b7a5f7d54.png)  
###in QT:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/4b28ea354f0f0f9d51db26553c63e5fe89e0b114.png)

###here is my code

```cpp
void BorderWidgetQt::openMPRwindow(QVTKWidget* qvtkwidget) {
	QVTKInteractor* iren = qvtkwidget->GetInteractor();
	vtkRenderWindow* renWin = qvtkwidget->GetRenderWindow();

	vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
	reader->SetDirectoryName("C:\\Users\\u\\source\\repos\\myrobotapp\\DICOM");
	reader->Update();

	vtkSmartPointer<vtkRenderer> ren; //vtksmartpointer 
	//vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
	renWin->SetMultiSamples(0);

	ren = vtkSmartPointer<vtkRenderer>::New();
	renWin->AddRenderer(ren);

	//vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	iren->SetRenderWindow(renWin);

	//renWin->SetInteractor(iren);
	vtkSmartPointer<vtkProperty> ipwProp = vtkSmartPointer<vtkProperty>::New();

	int imageDims[3];
	reader->GetOutput()->GetDimensions(imageDims);
	for (int i = 0; i < 3; i++) {
		std::cout << "imagesize L X W X H: " << imageDims[i] << std::endl;
	}

	vtkSmartPointer< vtkResliceCursor > resliceCursor = vtkSmartPointer< vtkResliceCursor >::New();
	resliceCursor->SetCenter(reader->GetOutput()->GetCenter());
	resliceCursor->SetThickMode(1);// mode 1 or more and thickness can be viewed 
	//set image that are resliced
	resliceCursor->SetImage(reader->GetOutput());

	vtkSmartPointer< vtkResliceCursorWidget > resliceCursorWidget;
	vtkSmartPointer< vtkResliceCursorLineRepresentation > resliceCursorRep;
	//camera viewup
	double viewUp[3][3] = { { 1, 0, -1 }, { 0, 0, 1 }, { 0, 1, 0 } };
	/ ************************ /
	resliceCursorWidget = vtkSmartPointer< vtkResliceCursorWidget >::New();
	resliceCursorWidget->SetInteractor(iren);

	resliceCursorRep = vtkSmartPointer< vtkResliceCursorLineRepresentation >::New();
	resliceCursorWidget->SetRepresentation(resliceCursorRep);
	resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetResliceCursor(resliceCursor);
	//thickness text is ediable and can turn off
	//resliceCursorRep->DisplayTextOff();
	resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetReslicePlaneNormal(0);
	cout << "number of input port: " << resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm() << endl;
	const double minVal = reader->GetOutput()->GetScalarRange()[0];
	std::cout << "minVal: " << minVal << " maxVal: " << reader->GetOutput()->GetScalarRange()[1] << endl; //0~1059

	if (vtkImageReslice *reslice = vtkImageReslice::SafeDownCast(resliceCursorRep->GetReslice()))
	{
		reslice->SetBackgroundColor(minVal, minVal, minVal, minVal);
	}

	resliceCursorWidget->SetDefaultRenderer(ren);
	resliceCursorWidget->SetEnabled(1);
	ren->GetActiveCamera()->SetFocalPoint(0, 0, 0);
	double camPos[3] = { 1, 0, 0 };
	ren->GetActiveCamera()->SetPosition(camPos);
	ren->GetActiveCamera()->ParallelProjectionOn();
	ren->GetActiveCamera()->SetViewUp(viewUp[0][0], viewUp[0][1], viewUp[0][2]);
	ren->ResetCamera();

	double range[2];
	reader->GetOutput()->GetScalarRange(range);
	std::cout << "range[0]: " << range[0] << " range[1]: " << range[1] << endl; // 0~1059
	//cover full range of window
	resliceCursorRep->SetWindowLevel(range[1] - range[0], (range[0] + range[1]) / 2.0);
	//resliceCursorRep->SetLookupTable(resliceCursorRep->GetLookupTable());
	//reslice cursor center
	vtkResliceCursor *rc = resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->GetResliceCursor();
	double *center = rc->GetCenter();
	std::cout << "cursor center: " << " [x]: "
		<< center[0] << " [y]: " << center[1] << " [z]: " << center[2] << endl;
	/ ************************ /

	//background of window
	ren->SetBackground(0.3, 0.1, 0.1);

	//whether it is a hole in the center of two cross hair
	resliceCursor->SetHole(0);
	resliceCursor->SetThickness(2, 2, 2);
	cout << "thickness is : " << resliceCursor->GetThickness()[0] << endl;

	vtkSmartPointer< vtkInteractorStyleImage > style = vtkSmartPointer< vtkInteractorStyleImage >::New();
	iren->SetInteractorStyle(style);
	renWin->Render();
	//iren->Initialize();
	//iren->Start();

}

```

---

<div class="post-metadata">

### Author: ![Alexandera](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@Alexandera](https://discourse.vtk.org/u/Alexandera)
#### Post date: [May 24, 2022, 3:18am UTC](https://discourse.vtk.org/t/vtkreslicecursorwidget-compatibility-with-qt-qvtkwidget/8562/2 "2022-05-24T03:18:40Z")

</div>

it was solved when I just claim the following in head file and make corresponding change in cpp:  
private:  
vtkSmartPointer\< vtkResliceCursorWidget \> resliceCursorWidget;  
I dont know the deepth of the solution. Maybe the QT cannot read the source file if it is not claimed, and also it needs timely render the source. I just closed this question.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/04204fe2b56cac93bb6a7138d9e5fff29f9e15bf.png)
