lazarus获取QT5当前所有可用的Style及设置指定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; //取当前Style Style:=QApplication_style; QObject_objectName(Style, @StyleName); //将style转为字符串 Memo1.Lines.Add(StyleName); StyleList:=QStringList_Create; QStyleFactory_keys(StyleList);//取当前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.

 
                    
                     
                    
                 
                    
                 

 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号