Index: interfaces/qt/qtint.pp
===================================================================
--- interfaces/qt/qtint.pp	(revision 11457)
+++ interfaces/qt/qtint.pp	(working copy)
@@ -52,9 +52,9 @@
 
   TQtWidgetSet = Class(TWidgetSet)
   private
-    App: QApplicationH;
     SavedDCList: TList;
   protected
+    App: QApplicationH;
     function CreateThemeServices: TThemeServices; override;
   public
     function LCLPlatform: TLCLPlatform; override;
Index: interfaces/qt/qtobjects.pas
===================================================================
--- interfaces/qt/qtobjects.pas	(revision 11457)
+++ interfaces/qt/qtobjects.pas	(working copy)
@@ -80,6 +80,7 @@
     constructor Create(Adata: PByte; width: Integer; height: Integer; format: QImageFormat); overload;
     destructor Destroy; override;
     function AsIcon(AMode: QIconMode = QIconNormal; AState: QIconState = QIconOff): QIconH;
+    function AsPixmap: QPixmapH;
   public
     function height: Integer;
     function width: Integer;
@@ -460,14 +461,19 @@
 var
   APixmap: QPixmapH;
 begin
-  APixmap := QPixmap_create();
-  QPixmap_fromImage(APixmap, Handle);
+  APixmap := AsPixmap;
   Result := QIcon_create();
   if Result <> nil then
     QIcon_addPixmap(Result, APixmap, AMode, AState);
   QPixmap_destroy(APixmap);
 end;
 
+function TQtImage.AsPixmap: QPixmapH;
+begin
+  Result := QPixmap_create();
+  QPixmap_fromImage(Result, Handle);
+end;
+
 {------------------------------------------------------------------------------
   Method: TQtImage.height
   Params:  None
@@ -1550,3 +1556,4 @@
 
 end.
 
+
Index: interfaces/qt/qtwidgets.pas
===================================================================
--- interfaces/qt/qtwidgets.pas	(revision 11457)
+++ interfaces/qt/qtwidgets.pas	(working copy)
@@ -35,23 +35,42 @@
   qtobjects,
   // Free Pascal
   Classes, SysUtils, Types,
+  // Widgetset
+  QtInt,
   // LCL
   LCLType, LCLProc, LCLIntf, LMessages, Buttons, Forms, Controls, ComCtrls, CommCtrl,
   ExtCtrls, StdCtrls, Menus;
 
+// forward declarations
 type
+  TQtTimer = class;
+
   TPaintData = record
     ClipRect: Prect;
     ClipRegion: QRegionH;
   end;
-  
-type
+
+  TCaretInfo = record
+    X: Integer;
+    Y: Integer;
+    Width: Integer;
+    Height: Integer;
+    Visible: Boolean;  // Caret is on
+    IsDrawn: Boolean;  // Caret is visible at the moment
+    Blinking: Boolean; // Caret should blink
+    Image: TQtImage;
+    BackImage: TQtImage;
+    Timer: TQtTimer;
+    ShowHideOnFocus: boolean; // true = hide on loose focus, show on get focus
+  end;
+
   { TQtWidget }
 
   TQtWidget = class(TObject)
   private
     FProps: TStringList;
     FPaintData: TPaintData;
+    FCaret: TCaretInfo;
     function GetProps(const AnIndex: String): pointer;
     function QtKeyToLCLKey(key: Integer): Word;
     procedure DeliverMessage(var Msg);
@@ -69,6 +88,19 @@
     destructor Destroy; override;
     function  GetContainerWidget: QWidgetH; virtual;
   public
+    // caret related
+    procedure CaretTimer;
+    procedure CreateCaret(AImage: TQtImage; AWidth, AHeight: Integer);
+    procedure DestroyCaret;
+    procedure DrawCaret(CalledByTimer: boolean);
+    function GetCaretPos(var APos: TPoint): Boolean;
+    function HideCaret: Boolean;
+    procedure InitCaret;
+    procedure SetCaretPos(AX, AY: Integer);
+    procedure ShowCaret;
+
+    property Caret: TCaretInfo read FCaret;
+  public
     function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; virtual;
     procedure SlotShow(vShow: Boolean); cdecl;
     procedure SlotClose; cdecl;
@@ -91,7 +123,8 @@
     procedure WindowTitle(Str: PWideString);
     procedure Hide;
     procedure Show;
-    function getVisible: boolean;
+    function getVisible: Boolean;
+    function hasFocus: Boolean;
     procedure setEnabled(p1: Boolean);
     procedure setVisible(visible: Boolean);
     function windowModality: QtWindowModality;
@@ -614,6 +647,9 @@
 {taCenter      } QtAlignHCenter
   );
 
+type
+  TQtWidgetsetAccess = class(TQtWidgetSet);
+
 { TQtWidget }
 
 {------------------------------------------------------------------------------
@@ -649,6 +685,8 @@
 
   // Set mouse move messages policy
   QWidget_setMouseTracking(Widget, True);
+  
+  InitCaret;
 end;
 
 {------------------------------------------------------------------------------
@@ -717,6 +755,196 @@
   Result := Widget;
 end;
 
+procedure TQtWidget.CaretTimer;
+begin
+  //DrawCaret(True);
+end;
+
+procedure TQtWidget.InitCaret;
+begin
+  with Caret do
+  begin
+    Visible := False;
+    IsDrawn := False;
+    Blinking := True;
+    X := 0;
+    Y := 0;
+    Width := 1;
+    Height := 10;
+    Image := nil;
+    BackImage := nil;
+    Timer := nil;
+    ShowHideOnFocus := true;
+  end;
+end;
+
+procedure TQtWidget.SetCaretPos(AX, AY: Integer);
+var
+  IsVisible: Boolean;
+begin
+  with Caret do
+  begin
+    IsVisible := Visible;
+    if IsVisible then
+      HideCaret;
+    X := AX;
+    Y := AY;
+    if IsVisible then
+      ShowCaret;
+  end;
+end;
+
+procedure TQtWidget.CreateCaret(AImage: TQtImage; AWidth, AHeight: Integer);
+var
+  IsVisible: Boolean;
+  WasVisible: boolean;
+  DC: TQtDeviceContext;
+begin
+  with Caret do
+  begin
+    IsVisible := Visible;
+    if IsVisible then
+      WasVisible := HideCaret;
+
+    if (Width <> AWidth) or (Height <> AHeight) then
+    begin
+      FreeAndNil(BackImage);
+      Width := AWidth;
+      Height := AHeight;
+    end;
+
+    Image := AImage;
+    
+    if Image = nil then
+    begin
+      // create own solid caret
+      {$note implement destroy Image if our own}
+      DC := TQtDeviceContext.Create(0);
+      Image := TQtImage.Create(QImage_create(Width, Height, QImageFormat_ARGB32));
+      DC.setImage(Image);
+      DC.SetBkColor(0);
+      DC.fillRect(0, 0, Width, Height);
+      DC.vImage := nil;
+      DC.Free;
+    end;
+
+    if IsVisible then
+      ShowCaret;
+  end;
+end;
+
+procedure TQtWidget.DestroyCaret;
+begin
+  with Caret do
+  begin
+    if Visible then
+      HideCaret;
+
+    FreeAndNil(BackImage);
+    Image := nil;
+  end;
+end;
+
+procedure TQtWidget.DrawCaret(CalledByTimer: boolean);
+var
+  AHasFocus: boolean;
+
+  procedure DrawToWidget(AImage: TQtImage);
+  var
+    SrcRect, DstRect: TRect;
+    DC: TQtDeviceContext;
+  begin
+    if (AImage <> nil) and (Widget <> nil) then
+      with Caret do
+      begin
+        DC := TQtDeviceContext.Create(THandle(Self));
+        SrcRect := Bounds(0, 0, Width, Height);
+        DstRect := Bounds(X, Y - 1, Width, Height);
+
+        DC.CorrectCoordinates(SrcRect);
+        DC.CorrectCoordinates(DstRect);
+        DC.drawImage(@DstRect, AImage.Handle, @SrcRect);
+        DC.Free;
+      end;
+  end;
+  
+  function GetWidgetImage: TQtImage;
+  var
+    Pixmap: QPixmapH;
+    WinID: LongWord;
+  begin
+    with Caret do
+    begin
+      Pixmap := QPixmap_create(Width, Height);
+      WinID := QWidget_winId(Widget);
+      QPixmap_grabWindow(Pixmap, WinID, X, Y - 1, Width, Height);
+      Result := TQtImage.Create(QImage_create());
+      QPixmap_toImage(Pixmap, Result.Handle);
+      QPixmap_destroy(Pixmap);
+    end;
+  end;
+  
+begin
+  with Caret do
+  begin
+    AHasFocus := hasFocus;
+
+    if (Timer <> nil) and ((not Blinking) or (not Visible) or (ShowHideOnFocus and (not AHasFocus))) then
+      FreeAndNil(Timer);
+
+    if IsDrawn and ((not Visible) or (Blinking and CalledByTimer)) then
+    begin
+      // hide caret
+      DrawToWidget(BackImage);
+      IsDrawn := False;
+    end
+    else
+    if Visible and (AHasFocus or (not ShowHideOnFocus)) and (not IsDrawn) then
+    begin
+      //Create backbitmap if needed
+      if (BackImage = nil) and (Width > 0) and (Height > 0) then
+        BackImage := GetWidgetImage;
+
+      // undraw old caret
+      DrawToWidget(BackImage);
+
+      // draw caret
+      if (Width > 0) and (Height > 0) then
+      begin
+        DrawToWidget(Image);
+        IsDrawn := True;
+      end;
+    end;
+
+    if Visible and Blinking and (Timer = nil) and ((not ShowHideOnFocus) or AHasFocus) then
+      Timer := TQtTimer.CreateTimer(500, CaretTimer, TQtWidgetsetAccess(QtWidgetSet).App);
+  end;
+end;
+
+function TQtWidget.GetCaretPos(var APos: TPoint): Boolean;
+begin
+  Result := Caret.Image <> nil;
+  APos.X := Caret.X;
+  APos.Y := Caret.Y;
+end;
+
+procedure TQtWidget.ShowCaret;
+begin
+  with Caret do
+  begin
+    FreeAndNil(Timer);
+    Visible := True;
+  end;
+  DrawCaret(False);
+end;
+
+function TQtWidget.HideCaret: Boolean;
+begin
+  Result := Caret.Visible;
+  FCaret.Visible := False;
+  DrawCaret(False);
+end;
+
 {$IFDEF VerboseQt}
 function EventTypeToStr(Event:QEventH):string;
 begin
@@ -1208,7 +1436,6 @@
   {$ifdef VerboseQt}
     WriteLn('TQtWidget.SlotPaint');
   {$endif}
-
   if (LCLObject is TWinControl) then
   begin
     FillChar(Msg, SizeOf(Msg), #0);
@@ -1376,6 +1603,11 @@
   Result := QWidget_isVisible(Widget);
 end;
 
+function TQtWidget.hasFocus: Boolean;
+begin
+  Result := QWidget_hasFocus(Widget);
+end;
+
 procedure TQtWidget.setEnabled(p1: Boolean);
 begin
   QWidget_setEnabled(Widget, p1);
@@ -4803,3 +5035,4 @@
 
 
 
+
Index: interfaces/qt/qtwinapi.inc
===================================================================
--- interfaces/qt/qtwinapi.inc	(revision 11457)
+++ interfaces/qt/qtwinapi.inc	(working copy)
@@ -335,6 +335,14 @@
   {$endif}
 end;
 
+function TQtWidgetSet.CreateCaret(Handle: HWND; Bitmap: hBitmap; width, Height: Integer): Boolean;
+begin
+  Result := Handle <> 0;
+
+  if Result then
+    TQtWidget(Handle).CreateCaret(TQtImage(Bitmap), Width, Height);
+end;
+
 {------------------------------------------------------------------------------
   Function: CreateCompatibleDC
   Params:  DC - handle to memory device context
@@ -647,6 +655,12 @@
   {$endif}
 end;
 
+function TQtWidgetSet.DestroyCaret(Handle: HWND): Boolean;
+begin
+  if Handle <> 0 then
+    TQtWidget(Handle).DestroyCaret;
+end;
+
 {------------------------------------------------------------------------------
   Method:  DestroyCursor
   Params:  Handle
@@ -951,6 +965,20 @@
 //  Desc^.LineEnd := rileDWordBoundary;
 end;
 
+function TQtWidgetSet.GetCaretPos(var lpPoint: TPoint): Boolean;
+var
+  Widget: TQtWidget;
+begin
+  Widget := QtObjectFromWidgetH(QApplication_focusWidget());
+  Result := (Widget <> nil) and Widget.GetCaretPos(lpPoint);
+end;
+
+function TQtWidgetSet.GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean;
+begin
+  {$note implement}
+  Result := inherited GetCaretRespondToFocus(handle, ShowHideOnFocus);
+end;
+
 {------------------------------------------------------------------------------
   Function: GetClientBounds
   Params: handle:
@@ -2229,6 +2257,13 @@
     AdjustForBuddySize;}
 end;
 
+function TQtWidgetSet.HideCaret(hWnd: HWND): Boolean;
+begin
+  Result := hWnd <> 0;
+  if Result then
+    TQtWidget(hWnd).HideCaret;
+end;
+
 {------------------------------------------------------------------------------
   Procedure: InitializeCriticalSection
   Params: var CritSection: TCriticalSection
@@ -2670,6 +2705,28 @@
   result := TQtDeviceContext(DC).SetBkMode(bkMode);
 end;
 
+function TQtWidgetSet.SetCaretPos(X, Y: Integer): Boolean;
+var
+  Widget: TQtWidget;
+begin
+  Widget := QtObjectFromWidgetH(QApplication_focusWidget());
+  Result := SetCaretPosEx(THandle(Widget), X, Y);
+end;
+
+function TQtWidgetSet.SetCaretPosEx(Handle: HWnd; X, Y: Integer): Boolean;
+begin
+  Result := Handle <> 0;
+  if Result then
+    TQtWidget(Handle).SetCaretPos(X, Y);
+end;
+
+function TQtWidgetSet.SetCaretRespondToFocus(handle: HWND;
+  ShowHideOnFocus: boolean): Boolean;
+begin
+  {$note implement}
+  Result := inherited SetCaretRespondToFocus(handle, ShowHideOnFocus);
+end;
+
 {------------------------------------------------------------------------------
   Function: SetCursor
   Params: ACursor - HCursor (QCursorH)
@@ -2759,6 +2816,13 @@
   Result := True;
 end;
 
+function TQtWidgetSet.ShowCaret(hWnd: HWND): Boolean;
+begin
+  Result := hWnd <> 0;
+  if Result then
+    TQtWidget(hWnd).ShowCaret;
+end;
+
 {------------------------------------------------------------------------------
   Method:  SetProp
   Params:  Handle -
@@ -3214,3 +3278,4 @@
 
 
 
+
Index: interfaces/qt/qtwinapih.inc
===================================================================
--- interfaces/qt/qtwinapih.inc	(revision 11457)
+++ interfaces/qt/qtwinapih.inc	(working copy)
@@ -34,6 +34,7 @@
 function CreateBitmap(Width, Height: Integer; Planes, BitCount: Longint; BitmapBits: Pointer): HBITMAP; override;
 function CreateBitmapFromRawImage(const RawImage: TRawImage; var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean): boolean; override;
 function CreateBrushIndirect(const LogBrush: TLogBrush): HBRUSH; override;
+function CreateCaret(Handle : HWND; Bitmap : hBitmap; width, Height : Integer) : Boolean; override;
 function CreateCompatibleDC(DC: HDC): HDC; override;
 function CreateCursor(ACursorInfo: PIconInfo): hCursor; override;
 function CreateFontIndirect(const LogFont: TLogFont): HFONT; override;
@@ -43,6 +44,7 @@
 
 procedure DeleteCriticalSection(var CritSection: TCriticalSection); override;
 function DeleteObject(GDIObject: HGDIOBJ): Boolean; override;
+function DestroyCaret(Handle : HWND): Boolean; override;
 function DestroyCursor(Handle: hCursor): Boolean; override;
 function DrawText(DC: HDC; Str: PChar; Count: Integer; var Rect: TRect; Flags: Cardinal): Integer; override;
 
@@ -57,6 +59,8 @@
 function FrameRect(DC: HDC; const ARect: TRect; hBr: HBRUSH): Integer; override;
 
 function GetBitmapRawImageDescription(Bitmap: HBITMAP; Desc: PRawImageDescription): Boolean; override;
+function GetCaretPos(var lpPoint: TPoint): Boolean; override;
+function GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean; override;
 function GetClientBounds(handle : HWND; var ARect : TRect) : Boolean; override;
 function GetClientRect(handle : HWND; var ARect : TRect) : Boolean; override;
 function GetClipBox(DC : hDC; lpRect : PRect) : Longint; override;
@@ -81,6 +85,8 @@
 function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
 function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override;
 
+function HideCaret(hWnd: HWND): Boolean; override;
+
 function InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean) : Boolean; override;
 procedure InitializeCriticalSection(var CritSection: TCriticalSection); override;
 
@@ -99,6 +105,9 @@
 function SelectObject(DC: HDC; GDIObj: HGDIOBJ): HGDIOBJ; override;
 function SetBKColor(DC: HDC; Color: TColorRef): TColorRef; override;
 function SetBkMode(DC: HDC; bkMode : Integer) : Integer; override;
+function SetCaretPos(X, Y: Integer): Boolean; override;
+function SetCaretPosEx(Handle: HWnd; X, Y: Integer): Boolean; override;
+function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean; override;
 function SetCursor(ACursor: HCURSOR): HCURSOR; override;
 function SetCursorPos(X, Y: Integer): Boolean; override;
 function SetFocus(hWnd: HWND): HWND; override;
@@ -106,6 +115,7 @@
 function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;
 function SetTextColor(DC: HDC; Color: TColorRef): TColorRef; override;
 function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;
+function ShowCaret(hWnd: HWND): Boolean; override;
 function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;
 function StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer;
   SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; ROp: Cardinal): Boolean; override;
@@ -120,3 +130,4 @@
 //##apiwiz##eps##   // Do not remove, no wizard declaration after this line
 
 
+
