CTK Widgets模块是CTK封装的用于通用功能以及生物医学成像专用领域的Qt组件库。
CTK中所有部分都有大量的测试相关代码,在源码目录下Libs/xxx/Testin/Cpp目录中。
CTK官方文档:
http://www.commontk.org/docs/html/modules.html
ImageGallery演示了CTK Widgets模块大部分组件的效果:
http://www.commontk.org/index.php/Documentation/ImageGallery
CTK Widgets模块主要包含4部分:
A、DICOM Widgets:用于支持医学数字影像通信(DICOM)领域的应用
B、Visualization VTK Widgets:支持VTK的组件
C、Widgets:通用的功能组件
D、XNAT Widgets:支持XNAT的组件
目前只包含一个类ctkXnatLoginDialog。
XNAT是华盛顿大学神经信息学研究小组开发的开源成像信息平台,最初在华盛顿大学的巴克纳实验室开发,目前由哈佛大学开发。
CTKWidgets模块使用与其它第三方库一样。
创建一个QtGUI应用并在工程文件中加入CTKWidgets模块。
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = HelloCTKWidget
TEMPLATE = app
#CTK安装路径
CTK_INSTALL_PATH = /usr/local
#CTK插件相关库所在路径
CTK_LIB_PATH = $$CTK_INSTALL_PATH/lib/ctk-0.1
#CTK插件相关头文件所在路径
CTK_INCLUDE_PATH = $$CTK_INSTALL_PATH/include/ctk-0.1
LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKWidgets
INCLUDEPATH += $$CTK_INCLUDE_PATH $$CTK_INCLUDE_FRAMEWORK_PATH
SOURCES += main.cpp Widget.cpp
HEADERS += Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QGridLayout>
#include <ctkCheckablePushButton.h>
#include <ctkCollapsibleButton.h>
#include <ctkColorPickerButton.h>
#include <ctkRangeWidget.h>
#include <ctkCollapsibleGroupBox.h>
#include <ctkCoordinatesWidget.h>
#include <ctkTreeComboBox.h>
#include <ctkSearchBox.h>
#include <ctkDirectoryButton.h>
#include <ctkCheckableComboBox.h>
#include <ctkMaterialPropertyWidget.h>
#include <ctkMatrixWidget.h>
#include <ctkPathLineEdit.h>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0)
{
m_layout = new QGridLayout(this);
//复选按钮
m_ctkCheckableButton = new ctkCheckablePushButton(this);
m_ctkCheckableButton->setText("ctkCheckablePushButton");
//可折叠按钮
m_ctkCollapsibleButton = new ctkCollapsibleButton(this);
m_ctkCollapsibleButton->setText("ctkCollapsibleButton");
m_layout->addWidget(m_ctkCheckableButton, 0, 0, 1, 2);
m_layout->addWidget(m_ctkCollapsibleButton, 0, 2, 1, 2);
//颜色拾取器
m_ctkColorPickerButton = new ctkColorPickerButton(this);
m_ctkColorPickerButton->setText("ctkColorPickerButton");
//滑块
m_ctkRangeWidget = new ctkRangeWidget(this);
m_layout->addWidget(m_ctkColorPickerButton, 1, 0, 1, 2);
m_layout->addWidget(m_ctkRangeWidget, 1, 2, 1, 2);
//分组框
m_ctkCollapsibleGroupBox = new ctkCollapsibleGroupBox(this);
m_ctkCollapsibleGroupBox->setTitle("GroupBox");
m_layout->addWidget(m_ctkCollapsibleGroupBox, 3, 0, 3, 4);
//坐标组件
m_ctkCoordinatesWidget = new ctkCoordinatesWidget(this);
//树形组合狂
m_ctkTreeComboBox = new ctkTreeComboBox(this);
m_ctkTreeComboBox->addItems(QStringList() << "A" << "B");
m_layout->addWidget(m_ctkCoordinatesWidget, 6, 0, 1, 2);
m_layout->addWidget(m_ctkTreeComboBox, 6, 2, 1, 2);
//搜索框
m_ctkSearchBox = new ctkSearchBox(this);
//目录按钮
m_ctkDirectoryButton = new ctkDirectoryButton(this);
m_layout->addWidget(m_ctkSearchBox, 7, 0, 1, 2);
m_layout->addWidget(m_ctkDirectoryButton, 7, 2, 1, 2);
//带复选功能的组合框
m_ctkCheckableComboBox = new ctkCheckableComboBox(this);
m_ctkCheckableComboBox->addItems(QStringList() << "A" << "B");
//路径行编辑框
m_ctkPathLineEdit = new ctkPathLineEdit(this);
m_ctkPathLineEdit->addCurrentPathToHistory();
m_layout->addWidget(m_ctkCheckableComboBox, 8, 0, 1, 2);
m_layout->addWidget(m_ctkPathLineEdit, 8, 2, 1, 2);
//材料属性组件
m_ctkMaterialPropertyWidget = new ctkMaterialPropertyWidget(this);
//矩阵组件
m_ctkMatrixWidget = new ctkMatrixWidget(this);
m_layout->addWidget(m_ctkMaterialPropertyWidget, 9, 0, 1, 2);
m_layout->addWidget(m_ctkMatrixWidget, 9, 2, 1, 2);
setLayout(m_layout);
}
private:
QGridLayout* m_layout;
ctkCheckablePushButton* m_ctkCheckableButton;
ctkCollapsibleButton* m_ctkCollapsibleButton;
ctkColorPickerButton* m_ctkColorPickerButton;
ctkRangeWidget* m_ctkRangeWidget;
ctkCollapsibleGroupBox* m_ctkCollapsibleGroupBox;
ctkCoordinatesWidget* m_ctkCoordinatesWidget;
ctkTreeComboBox* m_ctkTreeComboBox;
ctkSearchBox* m_ctkSearchBox;
ctkDirectoryButton* m_ctkDirectoryButton;
ctkCheckableComboBox* m_ctkCheckableComboBox;
ctkMaterialPropertyWidget* m_ctkMaterialPropertyWidget;
ctkMatrixWidget* m_ctkMatrixWidget;
ctkPathLineEdit* m_ctkPathLineEdit;
};
#endif // WIDGET_H
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
CTK Widgets测试代码位于CTK/Libs/Widgets/Testing/Cpp中,可以作为学习示例。
原文地址:http://blog.51cto.com/9291927/2120383