nana gui 控件拖拽

这篇博客介绍了如何在nana GUI库中实现控件的拖拽功能。通过使用gui::dragger,但因为一个dragger只能处理一个控件的拖拽状态,所以在创建多个控件时,需要在每个控件类中添加一个dragger成员,确保每个控件都有自己的dragger实例,并在构造函数中设置dragger指向自身。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

控件拖拽使用的是gui::dragger
操作方法是

dragger dg;
dg.trigger(*this);
dg.target(*this);

*this是控件
如果控件有好多,一个dragger无法操作多个控件,原因是一个dragger只记录了一个控件的拖拽状态。
所以可以在控件的类里增加一个dragger成员,这样每新建一个控件,就会伴随新建一个dragger。

#ifndef BLOCK_H
#define BLOCK_H
#include <nana/gui.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/dragger.hpp>
#include <string>
#include <vector>
using namespace nana;
using namespace std;
struct BlockInfo
{
    string name;
    string otype;
    vector<string> itype;
};
class Block:public button
{
    public:
        int id;
        string name;
        string itype;
        string otype;
        string getName();
        BlockInfo info;
        dragger dg;
        void setName(string s);
        string getFileName();
        bool isEmpty();
        Block(window f,int i,string s,int x,int y,int w,int h);
        virtual ~Block();
    protected:

    private:
};

#endif // BLOCK_H

在构造函数中把这个dragger指向自己

Block::Block(window f,int i,string s,int x,int y,int w,int h)
{
    name=s;
    id=i;
    create(f, rectangle(x, y, w, h));
    caption(s);
    dg.trigger(*this);
    dg.target(*this);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值