custom widget in qt

TstUsrCtrl.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
 
#include <qwidget>
 
class TstUsrCtrl : public QWidget
{
	Q_OBJECT
 
	QPoint oldPos_;
	QPoint curPos_;
 
public:
	explicit TstUsrCtrl(QWidget *parent = nullptr);
	~TstUsrCtrl();
 
	void paintEvent(QPaintEvent* event);
	void mousePressEvent(QMouseEvent* event);
	void mouseMoveEvent(QMouseEvent* event);
	void mouseReleaseEvent(QMouseEvent* event);
	void mouseToPosition(QMouseEvent* event);
};
</qwidget>

Read more

gtk user control自绘控件

ubuntu下gtk库是默认已安装的,开发部署很方便,以下是我写的自绘控件例子:

EuhatChildWnd.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
 
struct _cairo_surface;
struct _GtkWidget;
 
class EuhatChildWnd
{
public:
	EuhatChildWnd(int width, int height);
	~EuhatChildWnd();
 
	void clear();
	void drawBrush(struct _GtkWidget *widget, double x, double y);
 
	struct _GtkWidget *drawingArea_;
	struct _cairo_surface *surface_;
 
	double xFrom_;
	double yFrom_;
};

Read more

MFC重绘控件

举个按钮简单重绘的例子。

头文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class CMyButton : public CButton
{
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
 
class CMFCApplication1Dlg : public CDialogEx
{
	...
protected:
	virtual void DoDataExchange(CDataExchange* pDX);
	CMyButton m_myButton;
	...
};

Read more