diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 5b37997f84..f3a74ff059 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -1818,6 +1818,7 @@ const implementation uses + Buttons, qtCaret, qtproc, qtprivate, @@ -5509,8 +5510,6 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; end; function PaintBtn: Boolean; - const - IconDistance = 4; // hardcoded in qt libs (distance between icon and text) var APainter: QPainterH; R: TRect; @@ -5524,6 +5523,8 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; AText: WideString; DTFLAGS: DWord; ContentSize: TSize; + IconDistance: Integer; + IconMargin: Integer; begin Result := False; if (FIcon = nil) then @@ -5532,6 +5533,12 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; // paint button QObject_event(Widget, Event); + IconDistance := TCustomBitBtn(LCLObject).Spacing; + if IconDistance < 0 then + IconDistance := 4; {qt default} + + IconMargin := TCustomBitBtn(LCLObject).Margin; + // now we paint icon & text APainter := QPainter_create(QWidget_to_QPaintDevice(Widget)); AText := FText; @@ -5631,6 +5638,9 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; end else CenterOffset := ((R.Bottom - R.Top) div 2) - (ContentSize.cy div 2); + if IconMargin >= 0 then + CenterOffset := IconMargin; + if FText <> '' then begin if FGlyphLayout = 0 then @@ -5650,11 +5660,18 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; R := R2; if FGlyphLayout = 0 then - inc(R.Left, CenterOffset) + inc(R.Left, CenterOffset + IconDistance) else if FGlyphLayout = 1 then - dec(R.Right, CenterOffset); + dec(R.Right, CenterOffset + IconDistance) + else + if FGlyphLayout = 2 then + inc(R.Top, CenterOffset + IconDistance) + else + if FGlyphLayout = 3 then + dec(R.Bottom, CenterOffset + IconDistance); end; + if AText <> '' then QPainter_drawText(APainter, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, DTFlagsToQtFlags(DTFLAGS), @AText); diff --git a/lcl/interfaces/qt/qtwsbuttons.pp b/lcl/interfaces/qt/qtwsbuttons.pp index abbb4a0cff..b2519d4a36 100644 --- a/lcl/interfaces/qt/qtwsbuttons.pp +++ b/lcl/interfaces/qt/qtwsbuttons.pp @@ -42,6 +42,8 @@ type class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override; class procedure SetLayout(const ABitBtn: TCustomBitBtn; const AValue: TButtonLayout); override; + class procedure SetMargin(const ABitBtn: TCustomBitBtn; const AValue: Integer); virtual; + class procedure SetSpacing(const ABitBtn: TCustomBitBtn; const AValue: Integer); virtual; end; { TQtWSSpeedButton } @@ -130,4 +132,22 @@ begin TQtBitBtn(ABitBtn.Handle).Update(nil); end; +class procedure TQtWSBitBtn.SetMargin(const ABitBtn: TCustomBitBtn; + const AValue: Integer); +begin + if not WSCheckHandleAllocated(ABitBtn, 'SetMargin') then + Exit; + if TQtBitBtn(ABitBtn.Handle).getVisible then + TQtBitBtn(ABitBtn.Handle).Update(nil); +end; + +class procedure TQtWSBitBtn.SetSpacing(const ABitBtn: TCustomBitBtn; + const AValue: Integer); +begin + if not WSCheckHandleAllocated(ABitBtn, 'SetSpacing') then + Exit; + if TQtBitBtn(ABitBtn.Handle).getVisible then + TQtBitBtn(ABitBtn.Handle).Update(nil); +end; + end.