170 likes | 465 Views
Qt and Slicer. A short introduction September 16 th , 2009. Once upon a time …. Slicer developer got an awesome idea !. Slicer. Slicer developer contacted KWWidget. Slicer : I need this awesome Widget KWW :Will do my best … 3 to 4 weeks . Bottleneck !. Slicer. KWWidgets.
E N D
Qt and Slicer A short introduction September 16th, 2009
Once upon a time … • Slicer developer got an awesome idea ! Slicer
Slicer developer contacted KWWidget Slicer: I need this awesome Widget KWW :Will do my best … 3 to 4 weeks Bottleneck ! Slicer KWWidgets
In the mean time … QT Community QT Library Slicer: I need this awesome Widget KWW :Will do my best … 3 to 4 weeks Slicer & KWW: Ohhhhhhhh Slicer KWWidgets
They are a new kind of widgets Qt Double Slider Qt Color Picker Qt Thumbwheel • Super easy to derive, extend, customize, … • Super easy to learn • Plenty of documentation • Huge and active world wide community Slicer Bottleneck !
Outline • QT/Signal overview • VTK/QT interactions • UI creator - QtDesigner • Extending widget family • Using widget
QT signal/slot overview Class AppleTree: public Qobject Q_OBJECT signals: void ageChanged(int value);public slots: void incrementAge(); Private: int age; Connect(timer, SIGNAL(valueChanged()), tree, SLOT(incrementAge())) Connect(tree, SIGNAL(ageChanged(int)), jack, SLOT(checkTreeAge(int))) Class Lumberjack: public Qobject Q_OBJECT signals: void cutTreeDone(int value);public slots: void checkTreeAge(int v);
QT signal/slot overview (2) • Cmake provides a QObject wrapper SET(qSlicerGUI_SRCS main.cxx qSlicerMainWindow.h qSlicerMainWindow.cxx … ) # Headers that should run through moc SET(qSlicerGUI_MOC_SRCS qSlicerMainWindow.h … ) QT4_WRAP_CPP(qSlicerGUI_SRCS ${qSlicerGUI_MOC_SRCS})
VTK/QT interactions • VTK can call QT slot • QT can connect signal and slot • Slot is a regular C++ function • Slot can interact with any VTK objects • Connector = vtkEventQtSlotConnect::New() • Connector->Connect( representation, vtkCommand::PropertyModifiedEvent, • this,SLOT(onRepresentationPropertyModifiedEvent(vtkObject*, unsigned long, void*, void*)));
UI Creator: QtDesigner • QtDesigner -> XML File -> ui_MyWidget.h • Setup the graphic layout of widget • Possible to extend QtDesigner capabilities • Widget promotion • QtDesignerplugin • qSlicerAwesomeWidget: public Ui::Mywidget • Connect the widget with the application
UI Creator: Widget promotion • See http://doc.trolltech.com/4.5/designer-using-custom-widgets.html
UI Creator: Maverick and QtDesigner • A collection of opensource Qt Widgets • See http://www.vtk.org/Wiki/Maverick • See http://doc.trolltech.com/4.5/designer-creating-custom-widgets.html
Extending a widget family • Example: QmDoubleRangeWidget • Extend from QSlider • Overload paintEvent( QPaintEvent* ) • Set of convenient methods provided by Qt API • QStylePainter::drawComplexControl(…) • Cross Platform
Using widget from ‘others’ • Example QmDoubleRangeWidget • Developed by Karthik Krishnan • Self-documented interface • Signals and slots separation: Easy to understand • Cons: Handle only integers • Solution • Sub-classed into qSlicerDoubleRangeWidget
Let’s do it Thanks for your attention Question ? QT Community Slicer Qt Double Slider Qt Color Picker Qt Thumbwheel KWWidgets And they lived happily forever after …