• CTK框架 CTK Widgets快速入门


    CTK框架——CTK Widgets快速入门

    一、CTK Widgets模块简介

    1、CTK Widgets模块简介

    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

    2、CTK Widgets构成

    CTK Widgets模块主要包含4部分:
    CTK框架——CTK Widgets快速入门
    A、DICOM Widgets:用于支持医学数字影像通信(DICOM)领域的应用
    CTK框架——CTK Widgets快速入门
    B、Visualization VTK Widgets:支持VTK的组件
    CTK框架——CTK Widgets快速入门
    C、Widgets:通用的功能组件
    CTK框架——CTK Widgets快速入门
    CTK框架——CTK Widgets快速入门
    CTK框架——CTK Widgets快速入门
    CTK框架——CTK Widgets快速入门
    CTK框架——CTK Widgets快速入门
    D、XNAT Widgets:支持XNAT的组件
    目前只包含一个类ctkXnatLoginDialog。
    XNAT是华盛顿大学神经信息学研究小组开发的开源成像信息平台,最初在华盛顿大学的巴克纳实验室开发,目前由哈佛大学开发。

    二、CTK Widgets快速入门

    1、导入CTK Widgets模块

    CTKWidgets模块使用与其它第三方库一样。
    创建一个QtGUI应用并在工程文件中加入CTKWidgets模块。

     1 QT       += core gui
     2 
     3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
     4 
     5 TARGET = HelloCTKWidget
     6 TEMPLATE = app
     7 
     8 #CTK安装路径
     9 CTK_INSTALL_PATH = /usr/local/CTK
    10 
    11 #CTK插件相关库所在路径
    12 CTK_LIB_PATH = $$CTK_INSTALL_PATH/lib/ctk-0.1
    13 
    14 #CTK插件相关头文件所在路径
    15 CTK_INCLUDE_PATH = $$CTK_INSTALL_PATH/include/ctk-0.1
    16 
    17 LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKWidgets
    18 
    19 INCLUDEPATH += $$CTK_INCLUDE_PATH 
    20 
    21 SOURCES += main.cpp
    22         Widget.cpp
    23 
    24 HEADERS  += Widget.h

    2、使用CTK Widgets模块中的组件

     1 #ifndef WIDGET_H
     2 #define WIDGET_H
     3 
     4 #include <QWidget>
     5 #include <QGridLayout>
     6 
     7 #include <ctkCheckablePushButton.h>
     8 #include <ctkCollapsibleButton.h>
     9 #include <ctkColorPickerButton.h>
    10 #include <ctkRangeWidget.h>
    11 #include <ctkCollapsibleGroupBox.h>
    12 #include <ctkCoordinatesWidget.h>
    13 #include <ctkTreeComboBox.h>
    14 #include <ctkSearchBox.h>
    15 #include <ctkDirectoryButton.h>
    16 #include <ctkCheckableComboBox.h>
    17 #include <ctkMaterialPropertyWidget.h>
    18 #include <ctkMatrixWidget.h>
    19 #include <ctkPathLineEdit.h>
    20 
    21 class Widget : public QWidget
    22 {
    23     Q_OBJECT
    24 public:
    25     Widget(QWidget *parent = 0)
    26     {
    27         m_layout = new QGridLayout(this);
    28         //复选按钮
    29         m_ctkCheckableButton = new ctkCheckablePushButton(this);
    30         m_ctkCheckableButton->setText("ctkCheckablePushButton");
    31         //可折叠按钮
    32         m_ctkCollapsibleButton = new ctkCollapsibleButton(this);
    33         m_ctkCollapsibleButton->setText("ctkCollapsibleButton");
    34         m_layout->addWidget(m_ctkCheckableButton, 0, 0, 1, 2);
    35         m_layout->addWidget(m_ctkCollapsibleButton, 0, 2, 1, 2);
    36         //颜色拾取器
    37         m_ctkColorPickerButton = new ctkColorPickerButton(this);
    38         m_ctkColorPickerButton->setText("ctkColorPickerButton");
    39         //滑块
    40         m_ctkRangeWidget = new ctkRangeWidget(this);
    41         m_layout->addWidget(m_ctkColorPickerButton, 1, 0, 1, 2);
    42         m_layout->addWidget(m_ctkRangeWidget, 1, 2, 1, 2);
    43 
    44         //分组框
    45         m_ctkCollapsibleGroupBox = new ctkCollapsibleGroupBox(this);
    46         m_ctkCollapsibleGroupBox->setTitle("GroupBox");
    47         m_layout->addWidget(m_ctkCollapsibleGroupBox, 3, 0, 3, 4);
    48 
    49         //坐标组件
    50         m_ctkCoordinatesWidget = new ctkCoordinatesWidget(this);
    51 
    52         //树形组合狂
    53         m_ctkTreeComboBox = new ctkTreeComboBox(this);
    54         m_ctkTreeComboBox->addItems(QStringList() << "A" << "B");
    55         m_layout->addWidget(m_ctkCoordinatesWidget, 6, 0, 1, 2);
    56         m_layout->addWidget(m_ctkTreeComboBox, 6, 2, 1, 2);
    57         //搜索框
    58         m_ctkSearchBox = new ctkSearchBox(this);
    59         //目录按钮
    60         m_ctkDirectoryButton = new ctkDirectoryButton(this);
    61         m_layout->addWidget(m_ctkSearchBox, 7, 0, 1, 2);
    62         m_layout->addWidget(m_ctkDirectoryButton, 7, 2, 1, 2);
    63         //带复选功能的组合框
    64         m_ctkCheckableComboBox = new  ctkCheckableComboBox(this);
    65         m_ctkCheckableComboBox->addItems(QStringList() << "A" << "B");
    66         //路径行编辑框
    67         m_ctkPathLineEdit = new ctkPathLineEdit(this);
    68         m_ctkPathLineEdit->addCurrentPathToHistory();
    69         m_layout->addWidget(m_ctkCheckableComboBox, 8, 0, 1, 2);
    70         m_layout->addWidget(m_ctkPathLineEdit, 8, 2, 1, 2);
    71         //材料属性组件
    72         m_ctkMaterialPropertyWidget = new ctkMaterialPropertyWidget(this);
    73         //矩阵组件
    74         m_ctkMatrixWidget = new ctkMatrixWidget(this);
    75         m_layout->addWidget(m_ctkMaterialPropertyWidget, 9, 0, 1, 2);
    76         m_layout->addWidget(m_ctkMatrixWidget, 9, 2, 1, 2);
    77 
    78         setLayout(m_layout);
    79     }
    80 private:
    81     QGridLayout* m_layout;
    82     ctkCheckablePushButton* m_ctkCheckableButton;
    83     ctkCollapsibleButton* m_ctkCollapsibleButton;
    84     ctkColorPickerButton* m_ctkColorPickerButton;
    85     ctkRangeWidget* m_ctkRangeWidget;
    86     ctkCollapsibleGroupBox* m_ctkCollapsibleGroupBox;
    87     ctkCoordinatesWidget* m_ctkCoordinatesWidget;
    88     ctkTreeComboBox* m_ctkTreeComboBox;
    89     ctkSearchBox* m_ctkSearchBox;
    90     ctkDirectoryButton* m_ctkDirectoryButton;
    91     ctkCheckableComboBox* m_ctkCheckableComboBox;
    92     ctkMaterialPropertyWidget* m_ctkMaterialPropertyWidget;
    93     ctkMatrixWidget* m_ctkMatrixWidget;
    94     ctkPathLineEdit* m_ctkPathLineEdit;
    95 };
    96 
    97 #endif // WIDGET_H
     1 #include "Widget.h"
     2 #include <QApplication>
     3 
     4 int main(int argc, char *argv[])
     5 {
     6     QApplication a(argc, argv);
     7     Widget w;
     8     w.show();
     9 
    10     return a.exec();
    11 }

    3、CTK Widgets应用编译结果

    CTK框架——CTK Widgets快速入门

    4、CTK Widgets学习示例

    CTK Widgets测试代码位于CTK/Libs/Widgets/Testing/Cpp中,可以作为学习示例。

  • 相关阅读:
    Java并发包线程池之ThreadPoolExecutor
    Java并发包之线程池概述
    Java同步数据结构之ConcurrentHashMap
    new 操作符
    javascript-类型转换
    javascript-引用类型
    JS-数组与伪数组
    SVG-JS操作
    SVG-变换
    SVG-标签
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14235238.html
Copyright © 2020-2023  润新知