lazarus獲取QT5當(dāng)前所有可用的Style及設(shè)置指定style,直接上代碼:
unit Unit1; {$mode objfpc}{$H+} {$macro on} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls ,FileUtil, ExtCtrls{$ifdef lclqt5},qt5{$endif}; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; CheckBox1: TCheckBox; ComboBox1: TComboBox; Edit1: TEdit; Label1: TLabel; Memo1: TMemo; ProgressBar1: TProgressBar; RadioButton1: TRadioButton; procedure ComboBox1Change(Sender: TObject); procedure FormCreate(Sender: TObject); private public end; var Form1: TForm1; implementation uses LCLVersion, InterfaceBase, LCLPlatformDef; {$R *.lfm} { TForm1 } procedure TForm1.ComboBox1Change(Sender: TObject); {$ifdef lclqt5} var style:PWideString; {$endif} begin {$ifdef lclqt5} new(style); try style^:=ComboBox1.Text; QApplication_setStyle(style); finally Dispose(style); end; {$endif} end; procedure TForm1.FormCreate(Sender: TObject); {$ifdef LCLQT5} var Style: QStyleH; StyleName:WideString; StyleList:QStringListH; count,i:Integer; {$endif} begin Memo1.Lines.Clear; {$ifdef LCLQT5} Label1.Enabled:=True; ComboBox1.Enabled:=True; //取當(dāng)前Style Style:=QApplication_style; QObject_objectName(Style, @StyleName); //將style轉(zhuǎn)為字符串 Memo1.Lines.Add(StyleName); StyleList:=QStringList_Create; QStyleFactory_keys(StyleList);//取當(dāng)前QT5所有Sttyle count:=QStringList_size(StyleList); ComboBox1.Items.Clear; StyleName:=''; for i:=0 to count-1 do begin QStringList_at(StyleList,@StyleName,i); ComboBox1.Items.Add(StyleName); end; QStringList_destroy(StyleList); ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf('Fusion'); {$else} Label1.Enabled:=False; ComboBox1.Enabled:=False; {$endif} Memo1.Lines.Add(Format('Free Pascal version: %d.%d.%d for %s-%s', [FPC_VERSION, FPC_RELEASE, FPC_PATCH, lowercase({$i %FPCTARGETOS%}), lowercase({$i %FPCTARGETCPU%})]) ); Memo1.Lines.Add( Format('LCL version: %s', [lcl_version])); Memo1.Lines.Add( Format('LCL widgetset: %s', [LCLPlatformDisplayNames[WidgetSet.LCLPlatform]])); end; end.


浙公網(wǎng)安備 33010602011771號