gpt4 book ai didi

c++ - 我怎样才能将文件拖放到哪个 gtkmm 图像小部件

转载 作者:行者123 更新时间:2023-11-28 07:27:00 25 4
gpt4 key购买 nike

....
std::vector<Gtk::TargetEntry> listTargets;
listTargets.push_back( Gtk::TargetEntry("STRING") );
listTargets.push_back( Gtk::TargetEntry("text/plain") );

image1->drag_dest_set(listTargets);
image1->signal_drag_data_received().connect(sigc::mem_fun(*this,
&mainWindow::drop_event) );

image2->drag_dest_set(listTargets);
image2->signal_drag_data_received().connect(sigc::mem_fun(*this,
&mainWindow::drop_event) );
....

和我的 drop&drop 事件处理函数:

void mainWindow::drop_event(
const Glib::RefPtr<Gdk::DragContext>& context, int, int,
const Gtk::SelectionData& selection_data, guint, guint time)
{
std::cout << selection_data.get_data_as_string() << std::endl;
}

我可以使用此代码获取“拖动到图像小部件”的文件位置。输出是这样的:

file:////opt/google/chrome/google-chrome.desktop
file:////var/www/index.html
file:///opt/libreoffice4.1/LICENSE.html

没关系,我可以。但是,我怎样才能得到:文件放到哪个图像(image1 或 image2 小部件)是这样的:

dropped to **image1** : file:////opt/google/chrome/google-chrome.desktop
dropped to **image2** : file:////var/www/index.html
dropped to **image1** : file:///opt/libreoffice4.1/LICENSE.html

谢谢...

最佳答案

sigc allows you to bind extra arguments to your handlers.

处理程序变为:

void mainWindow::drop_event(
const Glib::RefPtr<Gdk::DragContext>& context, int, int,
const Gtk::SelectionData& selection_data, guint, guint time,
Glib::ustring whichImage)
{
std::cout << "dropped to" << whichImage << ":" << selection_data.get_data_as_string() << std::endl;
}

然后 connect 是:

image1->signal_drag_data_received().connect(sigc::bind<Glib::ustring>(sigc::mem_fun(*this,
&mainWindow::drop_event), "image1" ));

image2->signal_drag_data_received().connect( sigc::bind<Glib::ustring>(sigc::mem_fun(*this,
&mainWindow::drop_event), "image2"));

关于c++ - 我怎样才能将文件拖放到哪个 gtkmm 图像小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18592729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com