自定义控件时-添加多个控件到一组中

dmwidgetinterface.h

 1 #ifndef _DM_WIDGET_INTERFACE_H_
 2 #define _DM_WIDGET_INTERFACE_H_
 3
 4
 5 #include <QDesignerCustomWidgetInterface>
 6
 7
 8 // DM自定义控件
 9 class DmWidgetInterface : public QObject, public QDesignerCustomWidgetInterface
10 {
11     Q_OBJECT
12     Q_INTERFACES(QDesignerCustomWidgetInterface)
13
14 public:
15     DmWidgetInterface(const QString& className, QObject* parent = 0);
16     virtual ~DmWidgetInterface();
17
18     // 控件在Designer中显示的图标
19     virtual QIcon icon() const;
20
21     // 控件在Designer中显示的名称
22     virtual QString name() const;
23
24     // 控件在Designer中所在的组名称
25     virtual QString group() const;
26
27     // 控件在.ui文件中的默认描述
28     virtual QString domXml() const;
29
30     // 控件在Designer中鼠标悬浮时的提示信息
31     virtual QString toolTip() const;
32     virtual QString whatsThis() const;
33
34     // 控件是否是一个容器类控件,可以包容其他控件
35     virtual bool isContainer() const;
36
37 private:
38     // 类名
39     QString className;
40 };
41
42
43 // 生成控件接口类
44 #define DECLARE_WIDGET_INTERFACE(WidgetName) 45 46 class WidgetName##Interface : public DmWidgetInterface 47 { 48     Q_INTERFACES(QDesignerCustomWidgetInterface) 49 50 public: 51     WidgetName##Interface(QObject* parent = 0); 52     virtual ~WidgetName##Interface(); 53 54     virtual QString includeFile() const; 55 56     virtual QWidget* createWidget(QWidget* parent); 57 };
58
59
60 // 实现控件接口类
61 #define IMPLEMENT_WIDGET_INTERFACE(WidgetName, IncludeFile) 62 63 WidgetName##Interface::WidgetName##Interface(QObject* parent) : DmWidgetInterface(#WidgetName, parent) 64 { 65 66 } 67 68 WidgetName##Interface::~WidgetName##Interface() 69 { 70     71 } 72 73 QString WidgetName##Interface::includeFile() const 74 { 75     return (IncludeFile); 76 } 77 78 QWidget* WidgetName##Interface::createWidget(QWidget* parent) 79 { 80     return new WidgetName(parent); 81 }
82
83
84 #endif // _DM_WIDGET_INTERFACE_H_

dmwidgetinterface.cpp

 1 #include "dmwidgetinterface.h"
 2
 3
 4 DmWidgetInterface::DmWidgetInterface(const QString& name, QObject* parent)
 5     : QObject(parent), className(name)
 6 {
 7
 8 }
 9
10 DmWidgetInterface::~DmWidgetInterface()
11 {
12
13 }
14
15 // 控件在Designer中显示的图标
16 QIcon DmWidgetInterface::icon() const
17 {
18     return QIcon();
19 }
20
21 // 控件在Designer中显示的名称
22 QString DmWidgetInterface::name() const
23 {
24     return this->className;
25 }
26
27 // 控件在Designer中所在的组名称
28 QString DmWidgetInterface::group() const
29 {
30     return "DmWidgets";
31 }
32
33 // 控件在.ui文件中的默认描述
34 QString DmWidgetInterface::domXml() const
35 {
36     return QDesignerCustomWidgetInterface::domXml();
37 }
38
39 // 控件在Designer中鼠标悬浮时的提示信息
40 QString DmWidgetInterface::toolTip() const
41 {
42     return "";
43 }
44
45 QString DmWidgetInterface::whatsThis() const
46 {
47     return "";
48 }
49
50 // 控件是否是一个容器类控件,可以包容其他控件
51 bool DmWidgetInterface::isContainer() const
52 {
53     return false;
54 }

dmwidgetinterfaces.cpp

#include <QtCore/QtPlugin>

#include "dmtexteditinterface.h"

DmWidgetInterfaces::DmWidgetInterfaces(QObject* parent)
    : QObject(parent)
{
    // 多行文本输入
    this->widgets.append(new DmTextEditInterface(this));

}

DmWidgetInterfaces::~DmWidgetInterfaces()
{

}

// 控件列表
QList<QDesignerCustomWidgetInterface*> DmWidgetInterfaces::customWidgets() const
{
    return this->widgets;
}

Q_EXPORT_PLUGIN(DmWidgetInterfaces)

dmtextedit.h

#ifndef _DM_TEXT_EDIT_H
#define _DM_TEXT_EDIT_H

#include <QtGui/QTextEdit>

#include "libwidgets.h"

// 多行输入文本控件
class WIDGETS_EXPORT DmTextEdit : public QTextEdit
{
    Q_OBJECT 

public:
    DmTextEdit(QWidget* parent = 0);
    virtual ~DmTextEdit();

};
#endif

dmtexteditinterface.cpp

1 #include "dmtextedit.h"
2 #include "dmtexteditinterface.h"
3
4
5 // 多行输入文本控件
6 IMPLEMENT_WIDGET_INTERFACE(DmTextEdit, "dmtextedit.h")

dmtexteditinterface.h

 1 #ifndef _DM_TEXTEDIT_INTERFACE_H_
 2 #define _DM_TEXTEDIT_INTERFACE_H_
 3
 4
 5 #include "dmwidgetinterface.h"
 6
 7 // 多行输入的文本控件
 8 DECLARE_WIDGET_INTERFACE(DmTextEdit)
 9
10
11 #endif

时间: 2024-08-12 10:53:19

自定义控件时-添加多个控件到一组中的相关文章

在现有WinForms应用中添加C1Themes主题控件

在本博客中,展示了如何在现有的WinForms应用中添加C1Themes控件支持. 本文使用名为C1dView Samples的应用程序,它包含C1Reports.它是基于C1Ribbon界面设计的C1Report/C1PrintDocument浏览应用程序.该应用最初没有包含主题的支持. C1DView示例下载:C1dView.zip (94.96 kb) (下载次数: 7) 如下描述的简单的步骤,为最终用户提供在程序中选择使用包含于C1Themes控件产品中的若干主题的支持.(请注意:在进行

将MenuStrip控件中的信息添加到TreeView控件中【转载】

本文详细介绍怎样将MenuStrip控件中的信息添加到TreeView控件中 首先在WinForm窗体中添加一个MenuStrip控件和TreeView控件,根据个人的爱好把控件布局好后.在窗体的加载事件中(根据自己的情况而定)添加如下的代码: /// <summary>   /// 窗体加载时事件   /// </summary>   /// <param name="sender"></param>   /// <param n

[转]如何在数据绑定时不让combox控件触发SelectedIndexChanged事件

this.cboVendor.SelectedIndexChanged -= new System.EventHandler(this.cboVendor_SelectedIndexChanged); cboVendor.DataSource = myClass.RunQueryCmd(strSqlCmd); cboVendor.DisplayMember = "SupplierCode"; //添加事件 this.cboVendor.SelectedIndexChanged += n

DataGridView添加另外一个控件。

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Drawing; 5 using System.Data; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Xml; 10 11 namespace XjxMobilenursi

通过编写串口助手工具学习MFC过程&mdash;&mdash;(七)添加Tab Control控件

通过编写串口助手工具学习MFC过程 因为以前也做过几次MFC的编程,每次都是项目完成时,MFC基本操作清楚了,但是过好长时间不再接触MFC的项目,再次做MFC的项目时,又要从头开始熟悉.这次通过做一个串口助手再次熟悉一下MFC,并做了一下记录,以便方便以后查阅.做的过程中多是遇到问题直接百度和谷歌搜索来的,所以很多都是不求甚解,知其然不知其所以然.另外做此工具只是为了熟悉了解,许多功能还没有完善!(开发工具VS2008) (七)添加Tab Control控件 要在对话框里添加标签页,点击标签页上

关于xib中添加collection view 控件引起brash

首先这个问题我没有找到解决的办法,不知道问题出现在哪里,所以在这里贴个博文,看看有大神路过能把问题给解决了. 问题描述: 首先建立了一个新的项目,在stroyboard中添加collection view 控件,遵循其中 UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource协议,完成collection view 的显示,都很正常,一切OK,然后我添加一个viewcontrol

Qt编写自定义控件23-广告轮播控件

一.前言 广告轮播这个控件做的比较早,是很早以前定制一个电信客户端时候用到的,该客户端需要在首页展示轮播预先设定好的图片,图片的路径可以自由设定,然后轮播的间隔速度可以自由控制,同时该控件还需要提供两种指示器的风格,一种是迷你型的样式,一种是数字型的样式. 本控件很早就做好了,由于当时的QPainter功力不足,还不是很熟悉QPainter,采用的是效率比较低的直接用现有控件堆积而成,比如指示器采用的QLabel,用样式表来控制对应的形状,指示器所在的底部放一个widget,采用左右布局,然后右

iOS开发——UI高级OC篇&amp;自定义控件之调整按钮中子控件(图片和文字)的位置

自定义控件之调整按钮中子控件(图片和文字)的位置 其实还有一种是在storyBoard中实现的,只需要设置对应空间的左右间距: 这里实现前面两种自定义的方式 一:imageRectForContentRect/titleRectForContentRect 自定义一个按钮控件在系统自带的位置设置方法中实现对应子控件位置调整 1 /** 2 3 * 设置内部图标的frame 4 5 */ 6 7 - (CGRect)imageRectForContentRect:(CGRect)contentRe

WPF自定义控件与样式(10)-进度控件ProcessBar自定义样

一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: ProcessBar自定义标准样式: ProcessBar自定义环形进度样式: 二.ProcessBar标准样式 效果图: ProcessBar的样式非常简单: <!--ProgressBar Style--> <Style TargetType="ProgressBar" x