QtAda-将图像从一个表视图拖放到另一个表视图

QtAda-将图像从一个表视图拖放到另一个表视图,qt,drag-and-drop,qt4,tableview,ada,Qt,Drag And Drop,Qt4,Tableview,Ada,我是编程新手,刚刚开始学习Qtada 3.2,所以请原谅:D 我的目标是将图片(png)从一个表视图模型拖动到另一个表视图模型 虽然在下面的最小示例中,图像已经在拖动过程中显示,但我想覆盖鼠标按下和鼠标释放事件应该是解决方案? 我还需要做什么,比如创建删除操作、mime数据或项委托? 虽然我看过QtAda教程,但我仍然不知道如何正确设置表视图的覆盖事件。 真的试了很多,但都没用。现在我陷入了困境和困惑。 如果有人能给我指出正确的方向那就太好了,或者更好的是,给我一个工作的例子 额外问题#1:是否

我是编程新手,刚刚开始学习Qtada 3.2,所以请原谅:D

我的目标是将图片(png)从一个表视图模型拖动到另一个表视图模型

虽然在下面的最小示例中,图像已经在拖动过程中显示,但我想覆盖鼠标按下和鼠标释放事件应该是解决方案? 我还需要做什么,比如创建删除操作、mime数据或项委托? 虽然我看过QtAda教程,但我仍然不知道如何正确设置表视图的覆盖事件。 真的试了很多,但都没用。现在我陷入了困境和困惑。 如果有人能给我指出正确的方向那就太好了,或者更好的是,给我一个工作的例子

额外问题#1:是否有更好/更正确的方法将图像加载到项目模型中

附加问题#2:如何消除表中的行编辑?我只需要将图像显示在单元格中,其他什么都不需要

提前谢谢

迈克尔

我的例子是:

main.adb

with Qt4.Core_Applications;
with Qt4.Objects;
with Qt4.Push_Buttons.Constructors;
with Qt4.Splitters.Constructors;
with Qt4.Splitters;
with Qt4.Strings;
with Qt_Ada.Application;
with Table_View_Big;
with Table_View_Small;

procedure Main is

begin

   Qt_Ada.Application.Initialize;

   declare

      Quit   : constant not null access Qt4.Push_Buttons.Q_Push_Button'Class
        := Qt4.Push_Buttons.Constructors.Create
          (Qt4.Strings.From_Utf_16 ("Quit"));

      Splitter : constant not null Qt4.Splitters.Q_Splitter_Access
        := Qt4.Splitters.Constructors.Create(The_Orientation => Qt4.Vertical);

      Big_Table : constant not null Table_View_Big.Big_Table_Access
        := Table_View_Big.Constructors.Create;

      Small_Table : constant not null Table_View_Small.Small_Table_Access
        := Table_View_Small.Constructors.Create;

   begin

      Splitter.Add_Widget(Big_Table);
      Splitter.Add_Widget(Small_Table);
      Splitter.Add_Widget(Quit);

      Qt4.Objects.Connect (Quit,
                           Qt4.Signal ("clicked()"),
                           Qt4.Core_Applications.Instance,
                           Qt4.Slot ("quit()"));
      Splitter.Set_Fixed_Size(640,480);

      Splitter.Show;
      Qt_Ada.Application.Execute;

   end;

end Main;
表\u view\u small.ads:

with Qt4.Table_Views.Constructors;
with Qt4.Table_Views.Directors;
with Qt4.Abstract_Item_Models;
--with Qt4.Mouse_Events;

package Table_View_Small is

   type Small_Table is limited new Qt4.Table_Views.Q_Table_View with private;

   type Small_Table_Access is access all Small_Table'Class;

   package Constructors is

      function Create return not null Small_Table_Access;

   end Constructors;

private

   type Small_Table is new Qt4.Table_Views.Directors.Q_Table_View_Director with record

      Small_Table_Item_Model    : Qt4.Abstract_Item_Models.Q_Abstract_Item_Model_Access;

   end record;

   --     overriding procedure Mouse_Press_Event
   --       (Self  : not null access Table_Small;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);


   --     overriding procedure Mouse_Move_Event
   --       (Self  : not null access Table_Small;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);


   --     overriding procedure Mouse_Release_Event
   --       (Self  : not null access Table_Small;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);

end Table_View_Small;
表\u视图\u small.adb

with Qt4.Icons;
with Qt4.Model_Indices;
with Qt4.Standard_Item_Models.Constructors;
with Qt4.Strings;
with Qt4.Variants;
with Table_View_Small.MOC;
pragma Warnings (Off, Table_View_Small.MOC);


package body Table_View_Small is

   use Qt4;

   package body Constructors is

      function Create return not null Small_Table_Access is

         Self   : constant Table_View_Small.Small_Table_Access := new Table_View_Small.Small_Table;

      begin

         Qt4.Table_Views.Directors.Constructors.Initialize (Self);

         declare

            Icon : Qt4.Icons.Q_Icon;

            Data_Role : Qt4.Item_Data_Role := qt4.Decoration_Role;

            Index : Qt4.Model_Indices.Q_Model_Index;

         begin

            Self.Small_Table_Item_Model := Qt4.Abstract_Item_Models.Q_Abstract_Item_Model_Access
              (Qt4.Standard_Item_Models.Constructors.Create (1, 6, Self));

            Icon := Qt4.Icons.Create(Qt4.Strings.From_Ucs_4("anypng.png"));

            Index := Self.Small_Table_Item_Model.Index(0,0);

            Qt4.Abstract_Item_Models.Set_Data(Self.Small_Table_Item_Model,index,icon.To_Q_Variant,Data_Role);

            Self.Set_Model(Self.Small_Table_Item_Model);


            -- Drag & Drop

            Self.Set_Accept_Drops(true);

            Self.Set_Drag_Enabled(true);

            Self.Set_Drop_Indicator_Shown(true);

            -- Self.Set_Drag_Drop_Mode(Qt4.Abstract_Item_Views.Internal_Move);

            return Self;

         end;

      end Create;

   end Constructors;

   --     overriding procedure Mouse_Press_Event
   --       (Self  : not null access Small_Table;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class)
   --     is
   --     null;
   --     end Mouse_Press_Event;

end Table_View_Small;
表\视图\大广告

with Qt4.Table_Views.Constructors;
with Qt4.Table_Views.Directors;
with Qt4.Abstract_Item_Models;

package Table_View_Big is

   type Big_Table is limited new Qt4.Table_Views.Q_Table_View with private;

   type Big_Table_Access is access all Big_Table'Class;

   package Constructors is

      function Create return not null Big_Table_Access;

   end Constructors;

private

   type Big_Table is new Qt4.Table_Views.Directors.Q_Table_View_Director with record

      Big_Table_Item_Model    : Qt4.Abstract_Item_Models.Q_Abstract_Item_Model_Access;

   end record;

   --     overriding procedure Mouse_Press_Event
   --       (Self  : not null access Big_Table;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);
   --
   --     overriding procedure Mouse_Move_Event
   --       (Self  : not null access Big_Table;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);

   --     overriding procedure Mouse_Release_Event
   --       (Self  : not null access Big_Table;
   --        Event : not null access Qt4.Mouse_Events.Q_Mouse_Event'Class);

end Table_View_Big;
表\u视图\u big.adb

with Qt4.Abstract_Item_Views;
with Qt4.Sizes;
with Qt4.Standard_Item_Models.Constructors;
with Table_View_Big.MOC;
pragma Warnings (Off, Table_View_Big.MOC);


package body Table_View_Big is

   package body Constructors is

      function Create return not null Big_Table_Access is

         Self   : constant Table_View_Big.Big_Table_Access := new Table_View_Big.Big_Table;

      begin

         Qt4.Table_Views.Directors.Constructors.Initialize (Self);

         declare

         begin

            Self.Big_Table_Item_Model := Qt4.Abstract_Item_Models.Q_Abstract_Item_Model_Access
              (Qt4.Standard_Item_Models.Constructors.Create (25, 25, Self));

            Self.Set_Model(Self.Big_Table_Item_Model);

            Self.Set_Selection_Mode(Qt4.Abstract_Item_Views.No_Selection);


            -- Drag & Drop

            Self.Set_Accept_Drops(true);

            Self.Set_Drag_Enabled(false);

            Self.Set_Drop_Indicator_Shown(true);

            -- Self.Set_Drag_Drop_Mode (Qt4.Abstract_Item_Views.Drop_Only);

            return Self;

         end;

      end Create;

   end Constructors;

end Table_View_Big;
表\u视图\u视图\u测试\u dd.gpr

with "qt_gui";

project Table_View_Test_DD is

   type Build_Modes is ("Application", "Metadata");
   Build_Mode : Build_Modes := external ("BUILD_MODE");

   for Source_Dirs use (".", ".amoc");

   case Build_Mode is
      when "Application" =>
         for Main use ("main.adb");
         for Object_Dir use ".objs";
         for Exec_Dir use ".";

      when "Metadata" =>
         for Languages use ("Amoc");
         for Object_Dir use ".amoc";
         for Source_Files use ("table_view_small.ads",
                               "table_view_big.ads");

   end case;

   package Compiler is
      for Default_Switches ("Ada") use ("-g", "-gnat05");
   end Compiler;

   package IDE is
      for QtAda_Amoc_Invocation_Switch use "-XBUILD_MODE=Metadata";
   end IDE;

   -- for Languages use ("Ada");

   package Naming is
      for Casing use "lowercase";
   end Naming;

end Table_View_Test_DD;

欢迎来到SO。一个好问题的关键是尽量减少与问题无关的代码。请删除不相关的注释和空白,使代码更容易理解。