....
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) );
....
そして私のドロップ&ドロップイベントハンドラ関数:
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
ありがとう...