锘??xml version="1.0" encoding="utf-8" standalone="yes"?>麻豆av一区二区三区,欧美主播一区二区三区,国产日韩精品视频一区二区三区http://m.shnenglu.com/biao/category/10673.html zh-cnMon, 14 Sep 2009 00:13:08 GMTMon, 14 Sep 2009 00:13:08 GMT60Qt鑷畾涔塛idget: 鐢≦T鍒涘緩鏂伴鏍?/title><link>http://m.shnenglu.com/biao/archive/2009/09/14/96081.html</link><dc:creator>鏆楅噾瑁呭</dc:creator><author>鏆楅噾瑁呭</author><pubDate>Sun, 13 Sep 2009 23:00:00 GMT</pubDate><guid>http://m.shnenglu.com/biao/archive/2009/09/14/96081.html</guid><wfw:comment>http://m.shnenglu.com/biao/comments/96081.html</wfw:comment><comments>http://m.shnenglu.com/biao/archive/2009/09/14/96081.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/biao/comments/commentRss/96081.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/biao/services/trackbacks/96081.html</trackback:ping><description><![CDATA[<span style="color: rgb(51, 51, 51); font-family: Tahoma, Arial, Helvetica, snas-serif; font-size: 14px; line-height: 25px; "><strong style="word-break: break-all; line-height: normal; ">1錛嶲t鐨勯鏍?/strong><br style="word-break: break-all; line-height: normal; ">銆銆a) Qt綆浠?br style="word-break: break-all; line-height: normal; ">銆銆Qt鏄竴涓法騫沖彴鐨凜++鍥懼艦鐢ㄦ埛鐣岄潰搴旂敤紼嬪簭寮鍙戝簱錛屼嬌鐢≦t鍙互寮鍙戝嚭楂樿川閲忕殑鍥懼艦鐢ㄦ埛鎺ュ彛錛屽畠鏄畬鍏ㄩ潰鍚戝璞$殑銆佹槗浜庢墿灞曚笖鍏佽鐪熸鐨勭粍浠剁紪紼嬨俀t鑾峰緱浜嗗緢澶х殑鎴愬姛錛岀壒鍒槸瀹冪殑淇″彿-妲芥満鍒舵槸闈炲父鍊煎緱鐮旂┒鐨勯氫俊鏈哄埗錛屽畠涔熸槸Linux鍙戣鐗堟爣鍑嗙粍浠禟DE(K Desktop Enviroment)鐨勫熀紜銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆b) 椋庢牸鏈哄埗<br style="word-break: break-all; line-height: normal; ">銆銆Qt鐨勯鏍兼満鍒跺疄鐜頒簡涓嶅悓騫沖彴涓婄殑鍥懼艦鐢ㄦ埛鎺ュ彛錛圙UI錛夌殑瑙傛劅錛坙ook and feel錛?渚嬪Windows騫沖彴涓婇氬父浣跨敤Windows鎴朩indows-xp椋庢牸錛岃孶nix騫沖彴涓婇氬父浣跨敤Motif銆丆DE椋庢牸銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆涓嬪浘鏄劇ず浜哘t涓笌椋庢牸鐩稿叧鐨勭被鐨勭戶鎵垮叧緋?br style="word-break: break-all; line-height: normal; ">銆銆銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452007056.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆QStyle鏄墍鏈夐鏍肩被鐨勫熀綾伙紝瀹冩帶鍒剁潃鎵鏈夌殑閮ㄤ歡錛坵idget鍗硍indows緙栫▼涓殑鎺т歡錛夌殑鐣岄潰椋庢牸鎴栬鎰燂紝瀹冨畾涔変簡澶ч噺鐨勬灇涓劇被鍨嬪拰鍗佸嚑涓嚱鏁般傛灇涓劇被鍨嬭〃紺虹晫闈笂鐨勪笉鍚屽厓绱狅紙濡傜粍鍚堟涓殑鎸夐挳錛屾寜閽殑杈規絳夛級錛涘嚱鏁版帶鍒跺浘褰㈢敤鎴風晫闈㈢殑緇樺埗錛屼絾澶у鏁板嚱鏁板熀鏈笂鍙槸涓浜涘0鏄庤屾病鏈夊嚱鏁板疄鐜幫紝浠栦滑鐨勫疄鐜板湪QCommonStyle銆丵WindowStyle銆丵MotifStyle鍙婂叾瀛愮被涓俀Style鍙疄鐜頒簡3涓嚱鏁癲rawItem()," itemRect(), visualRect()銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆drawItem(): 璐熻矗緇樺埗鏂囨湰鍜岃薄绱犲浘銆?br style="word-break: break-all; line-height: normal; ">銆銆itemRect(): 榪斿洖鏂囨湰鎴栧浘鍍忔墍鍗犵殑鍖哄煙銆?br style="word-break: break-all; line-height: normal; ">銆銆visualRect(): 榪斿洖閫昏緫鍧愭爣錛岃繖涓嚱鏁頒嬌Qt瀹炵幇right-to-left椋庢牸錛堥樋鏂囥佺淮鏂囦紶緇熸槸鏂囨湰浠庡彸鍚戝乏鏄劇ず錛屽洜姝ゆ帶浠跺竷灞涔熸槸浠庡彸鍚戝乏錛夈傚涓嬪浘鎵紺猴細<br style="word-break: break-all; line-height: normal; ">銆銆銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452005334.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆鍙互鐪嬪埌鑿滃崟銆佸伐鍏鋒潯鏄彸瀵歸綈銆佸崟閫夋鐨勬寜閽湪鍙寵竟<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆c)" 鍒涘緩鏂伴鏍肩殑姝ラ<br style="word-break: break-all; line-height: normal; ">銆銆鍦≦t涓疄鐜頒竴縐嶆柊椋庢牸鐨勬楠ゅ緢綆鍗曪細鍙渶閫夋嫨涓涓鏍肩被錛堝QCommonStyle鎴朡Style錛変綔涓虹埗綾伙紝鐒跺悗瀹炵幇鎰熷叴瓚g殑鍑芥暟鍗沖彲銆傞毦鐐瑰湪浜庡嚱鏁扮殑瀹炵幇銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆閫夋嫨鐖剁被錛氬彲浠ラ夋嫨QStyle, QCommonStyle, QWindowStyle, QMotifStyle浠ュ強浠栦滑鐨勫瓙綾葷殑浠繪剰涓涓綔涓虹埗綾匯傞氬父鍙互閫夋嫨QWindowsStyle鎴朡MotifStyle錛屼篃鍙互閫夋嫨QCommonStyle鐢氳嚦鏄疩Style錛屼絾鏄伐浣滈噺浼氭瘮杈冨ぇ錛屽洜涓哄緢澶氱晫闈㈢殑緇嗚妭闇瑕佽嚜宸卞疄鐜般?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆閲嶆柊瀹炵幇蹇呰鐨勫嚱鏁幫細鎯充慨鏀圭晫闈㈤鏍肩殑鍝儴鍒嗭紝灝遍噸鏂板疄鐜頒笌緇樺埗閭i儴鍒嗙浉鍏崇殑鍑芥暟錛屼笅闈㈣В閲婁竴涓嬫垜浠閲嶈澆鐨凲Style涓殑鍑犱釜鍑芥暟錛岃繖鍑犱釜鍑芥暟鎺у埗鐫鍥懼艦鐢ㄦ埛鐣岄潰涓婁笉鍚屽厓绱犵殑甯冨眬鍜岃鎰熴?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆 1錛塿oid drawPrimitive( PrimitiveElement pe,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆 QPainter *p,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QRect & r,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QColorGroup & cg,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆SFlags flags = Style_Default,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QStyleOption &opt = QStyleOption::Default ) ;<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鍔熻兘錛氱粯鍒跺熀鏈浘褰㈠厓绱狅紝濡俀SpinBox涓殑甯︾澶寸殑鎸夐挳銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452005795.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; ">絳夈?br style="word-break: break-all; line-height: normal; ">銆銆鍙傛暟錛? PrimitiveElement pe: 榪欎釜鏋氫婦鍨嬪彉閲忚〃紺哄皢瑕佺粯鍒剁殑鍩烘湰鍥懼艦鐣岄潰鍏冪礌錛堣繖閲岃鐨勫熀鏈浘褰㈢敤鎴風晫闈㈠厓绱犳寚GUI涓笉鍙啀鍒嗙殑涓涓師瀛愬厓绱狅紝濡傜粍鍚堟銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452002895.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; ">涓殑榪欎釜緇樻湁榛戣壊涓夎褰㈢殑鎸夐挳錛宻pinBox涓殑鎸夐挳銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452003019.gif%22" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆QPainter *p錛氭寚鍚慟Painter綾葷殑鎸囬拡錛孮t涓殑鎵鏈夌粯鍒舵搷浣滀笉綆℃槸緇樺埗鏂囨湰銆佸浘褰㈣繕鏄浘鍍忛兘鐢辮繖涓被鏉ュ鐞嗐?br style="word-break: break-all; line-height: normal; ">銆銆QRect &r: 琛ㄧず涓涓煩褰㈠尯鍩燂紝Qt鍦ㄨ繖涓尯鍩熶腑緇樺埗鍩烘湰鐣岄潰鍏冪礌錛圥rimitiveElement錛?<br style="word-break: break-all; line-height: normal; ">銆銆QColorGroup &cg: QColorGroup琛ㄧず涓涓儴浠?widget)鐨勯鑹茬粍錛坈olor group錛夛紝color group鍚湁閮ㄤ歡緇樺埗鑷繁鏃朵嬌鐢ㄧ殑鍚勭棰滆壊錛岃濡傚墠鏅壊鑳屾櫙鑹茬瓑銆備笅鍥懼睍紺轟簡color group涓殑鍚勭棰滆壊灞炴?br style="word-break: break-all; line-height: normal; ">銆銆銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452007748.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆SFlags" flags: 鎺у埗濡備綍緇樺埗鍥懼艦鐣岄潰鍏冪礌鐨勬爣蹇椼?br style="word-break: break-all; line-height: normal; ">銆銆QStyleOption &opt: 緇樺埗涓嶅悓鐨勯儴浠?widget)鏃朵細闇瑕佷笉鍚岀殑鍙傛暟錛屽緇樺埗闈㈡澘錛坧anel錛夊彲鑳介渶瑕佺嚎瀹戒綔涓洪澶栧弬鏁拌岀粯鍒剁劍鐐圭煩褰紙focus rect錛夊彲鑳介渶瑕佽儗鏅壊浣滀負棰濆鍙傛暟錛屾墍浠t涓撻棬鎻愪緵浜嗕竴涓被QStyleOption鏉ュ皝瑁呬笉鍚岀殑widget鍙兘闇瑕佺殑涓嶅悓鐨勫弬鏁幫紝opt鎸囧悜榪欐牱涓涓被鐨勫璞°?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆2錛塿oid drawComplexControl( ComplexControl control,<br style="word-break: break-all; line-height: normal; ">銆銆QPainter *p,<br style="word-break: break-all; line-height: normal; ">銆銆const QWidget *widget,<br style="word-break: break-all; line-height: normal; ">銆銆const QRect &r,<br style="word-break: break-all; line-height: normal; ">銆銆const QColorGroup &cg,<br style="word-break: break-all; line-height: normal; ">銆銆SFlags flags = Style_Default,<br style="word-break: break-all; line-height: normal; ">銆銆SCFlags controls = QStyle::SC_All,<br style="word-break: break-all; line-height: normal; ">銆銆SCFlags active = QStyle::SC_None,<br style="word-break: break-all; line-height: normal; ">銆銆const QStyleOption& opt = QStyleOption::Default)<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 <br style="word-break: break-all; line-height: normal; ">銆銆鍔熻兘錛氱粯鍒跺鏉傛帶鍒墮儴浠訛紙widget錛夊SpinWidget錛宑omboBox錛宻lider錛宭istView絳?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鍙傛暟錛?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆ComplexControl control錛氭槸涓涓灇涓鵑噺錛岃〃紺哄皢瑕佺粯鍒剁殑澶嶆潅鎺у埗閮ㄤ歡錛坵idget錛夊緇勫悎妗嗐佸垪琛ㄦ絳夈?br style="word-break: break-all; line-height: normal; ">銆銆QPainter *p錛氭寚鍚慟Painter鐨勬寚閽堬紝Qt涓殑鎵鏈夌粯鍒舵搷浣滀笉綆℃槸緇樺埗鏂囨湰銆佸浘褰㈣繕鏄浘鍍忛兘鐢辮繖涓被鏉ュ鐞嗐?br style="word-break: break-all; line-height: normal; ">銆銆QWidget *widget錛氭寚鍚慟Wdget鎴栧叾瀛愮被鐨勬寚閽堬紝鍙互鏍規嵁涓婇潰control鐨勫艱漿鍙橈紙cast錛夋垚鍚堥傜殑綾誨瀷錛屼緥濡傚鏋滆緇樺埗QSpinWidget錛岄偅涔坈ontrol鍙栧間負CC_SpinWidget,鑰寃idget鎸囧悜涓涓猀SpinWidget(QWidget鐨勫瓙綾?鐨勫疄渚嬶紙instance錛夈備嬌鐢ㄨ繖涓彉閲忓彲浠ヨ闂甉SpinWidget鐨勬垚鍛樺嚱鏁板拰鎴愬憳鍙橀噺錛岃濡傚彲浠ヨ皟鐢≦SpinWidget鐨剆izeHint鍑芥暟鑾峰緱榪欎釜閮ㄤ歡鐨勭己鐪佸ぇ灝忥紙涓涓煩褰㈢┖闂達級銆?br style="word-break: break-all; line-height: normal; ">銆銆QRect &r: 琛ㄧず涓涓煩褰㈠尯鍩燂紝Qt鍦ㄨ繖涓尯鍩熶腑緇樺埗鎺т歡鎴栧叾瀛愰儴浠躲?br style="word-break: break-all; line-height: normal; ">銆銆QColorGroup &cg: QColorGroup琛ㄧず涓涓儴浠?widget)鐨勯鑹茬粍錛坈olor group錛夛紝color group鍚湁閮ㄤ歡緇樺埗鑷繁鏃朵嬌鐢ㄧ殑鍚勭棰滆壊錛岃濡傚墠鏅壊鑳屾櫙鑹茬瓑銆?br style="word-break: break-all; line-height: normal; ">銆銆SFlags flags: 鎺у埗濡備綍緇樺埗鍥懼艦鐣岄潰鍏冪礌鐨勬爣蹇?br style="word-break: break-all; line-height: normal; ">銆銆SCFlags controls琛ㄧず緇樺埗澶嶆潅鎺у埗閮ㄤ歡control鐨勫摢涓瓙閮ㄤ歡錛岀己鐪佷負SC_All,鍗崇粯鍒舵暣涓猚ontrol鑰屼笉鏄叾鏌愪釜瀛愰儴浠訛紙娉ㄦ剰control, controls鏄袱涓笉鍚岀殑鍙傛暟錛?br style="word-break: break-all; line-height: normal; ">銆銆QStyleOption &opt: 鍦ㄧ粯鍒朵笉鍚岀殑閮ㄤ歡鏃跺彲鑳介渶瑕佷笉鍚岀殑棰濆鐨勫弬鏁幫紝榪欎釜鍙橀噺鍦ㄧ粯鍒朵笉鍚岀殑widget鏃舵彁渚涗笉鍚岀殑淇℃伅銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆3) QRect querySubControlMetrics(ComplexControl control,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆const QWidget* widget,<br style="word-break: break-all; line-height: normal; ">銆銆SubControl sc,<br style="word-break: break-all; line-height: normal; ">銆銆const QStyleOption& = QStyleOption::Default)<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鍔熻兘錛氳幏鍙栧瓙閮ㄤ歡鐨勫潗鏍囧拰灝哄淇℃伅銆傝繖涓嚱鏁版帶鍒剁潃涓涓鏉傛帶浠剁殑甯冨眬錛岄噸杞借繖涓嚱鏁板彲浠ヤ嬌鐨勭粍鍚堟鐨勪笅鎷夋寜閽粯鍒跺湪宸﹁竟 鑰屼笉鏄粯璁ょ殑鍙寵竟銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鍙傛暟錛?br style="word-break: break-all; line-height: normal; ">銆銆ComplexControl control: 鏋氫婦閲忥紝琛ㄧず灝嗚緇樺埗鐨勫鏉傛帶鍒墮儴浠訛紙widget錛夊緇勫悎妗嗐佸垪琛ㄦ絳夈?br style="word-break: break-all; line-height: normal; ">銆銆QWidget *widget錛氭寚鍚慟Widget鎴栧叾瀛愮被鐨勬寚閽堬紝鍙互鏍規嵁涓婇潰control鐨勫艱漿鍙橈紙cast錛夋垚鍚堥傜殑綾誨瀷錛屼緥濡傚鏋滆緇樺埗QSpinWidget錛岄偅涔坈ontrol鍙栧間負CC_SpinWidget,鑰寃idget鎸囧悜涓涓猀SpinWidget(QWidget鐨勫瓙綾?鐨勫疄渚嬨備嬌鐢ㄨ繖涓彉閲忓彲浠ヨ闂甉SpinWidget鐨勬垚鍛樺嚱鏁板拰鎴愬憳鍙橀噺錛岃濡傚彲浠ヨ皟鐢≦SpinWidget鐨剆izeHint鍑芥暟鑾峰緱榪欎釜閮ㄤ歡鐨勭己鐪佸ぇ灝忥紙涓涓煩褰㈢┖闂達級銆?br style="word-break: break-all; line-height: normal; ">銆銆SubControl sc錛氭灇涓鵑噺錛屼竴涓鏉傞儴浠跺彲鑳界敱澶氫釜鐨勫瓙閮ㄤ歡緇勬垚錛屼嬌鐢╯c鍙橀噺璇存槑瑕佽幏鍙栭偅涓瓙閮ㄤ歡鐨勫潗鏍囧拰灝哄淇℃伅銆?br style="word-break: break-all; line-height: normal; ">銆銆QStyleOption &opt: 璁$畻涓嶅悓閮ㄤ歡鐨勫昂瀵告椂鍙兘闇瑕佷笉鍚岀殑棰濆淇℃伅,QStyleOption灝佽浜嗚繖浜涗俊鎭?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<strong style="word-break: break-all; line-height: normal; ">2錛庡垱寤烘柊椋庢牸</strong><br style="word-break: break-all; line-height: normal; ">銆銆涓嬮潰鐢ㄤ竴涓緥瀛愭潵浠嬬粛涓涓嬪垱寤烘柊椋庢牸鐨勬暣涓繃紼嬶紝鍦ㄧ紪紼嬩箣鍓嶏紝鍏堢湅涓涓嬫渶緇堢殑緇撴灉鏄粈涔堟牱鐨勩?鍦≦t鍐呴儴QSpinBox綾繪槸閫氳繃QSpinWidget瀹炵幇鐨?<br style="word-break: break-all; line-height: normal; ">銆銆榛樿椋庢牸鐨勬晥鏋滐細銆<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/20050526145200140.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; ">浣跨敤鏂伴鏍肩殑鏁堟灉錛氥<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452007607.gif%22" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆鍙互鐪嬪埌鍦ㄦ柊椋庢牸涓垜浠殑SpinBox鏈変簡鍨傜洿鏄劇ず鐨勬晥鏋溿備笅闈㈡垜浠寜涓婇潰璇存槑鐨勬楠ゆ潵鍒涘緩涓縐嶆柊鐨勯鏍箋?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆1錛夐夋嫨鍩虹被錛氭垜浠夋嫨QWindowsStyle綾諱綔涓烘垜浠柊椋庢牸綾葷殑鍩虹被錛屽綋鐒朵篃鍙互閫夋嫨QMotifStyle錛屽湪榪欎釜渚嬪瓙縐嶄篃鍙互閫夋嫨QCommonStyle銆備竴鑸笉寤鴻閫夋嫨QCommonStyle浣滀負鍩虹被錛屽洜涓篞CommonStyle鍙疄鐜頒簡涓閮ㄥ垎鐣岄潰閮ㄤ歡錛屽鏋滆瀹炵幇涓涓畬鏁寸殑椋庢牸綾伙紝鎴戜滑闇瑕侀噸鏂板啓寰堝浠g爜銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆2錛夐噸杞界浉鍏崇殑鍑芥暟錛氬湪榪欎釜渚嬬▼涓垜浠彧淇敼浜唖pinBox鐨勯鏍鹼紝瀹炵幇榪欎釜閮ㄤ歡錛坵idget錛夊彧涓嶲Style綾葷殑涓変釜鍑芥暟drawPrimitive, drawComplexControl, qureySubControlMerics鐩稿叧錛屾墍浠ユ垜浠彧闇閲嶈澆榪欎笁涓嚱鏁扮殑鐩稿叧閮ㄥ垎浠g爜.涓嬮潰瀵逛唬鐮佷腑鐨勫叧閿儴鍒嗗仛涓涓嬫敞閲婏紝涓嶉噸瑕佺殑閮ㄥ垎鐪佺暐浜嗐傝緇嗙殑浠g爜鍙互浠庡悗闈笅杞姐?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆緇樺埗spinbox涓寜閽殑鍑芥暟錛?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆void CustomStyle::drawPrimitive( PrimitiveElement pe,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆QPainter * p,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QRect & r,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QColorGroup & cg,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆SFlags flags,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆const QStyleOption & opt ) const<br style="word-break: break-all; line-height: normal; ">銆銆{<br style="word-break: break-all; line-height: normal; ">銆銆/*PE_SpinWidgetUp,PE_SpinWidgetDown琛ㄧずspinBox涓殑涓嬫寜閽拰涓婃寜閽紝涓嬮潰鐨勪唬鐮佷嬌寰楄繖涓や釜鎸夐挳涓殑涓夎褰㈠垎鍒悜宸﹀拰鍚戝彸*/<br style="word-break: break-all; line-height: normal; ">銆銆if ((pe == PE_SpinWidgetUp) || (pe == PE_SpinWidgetDown)){<br style="word-break: break-all; line-height: normal; ">銆銆int fw = pixelMetric( PM_DefaultFrameWidth, 0 );//fw琛ㄧず杈規瀹藉害錛岄粯璁や負2<br style="word-break: break-all; line-height: normal; ">銆銆QRect br;銆//spinBox涓婃寜閽殑杈圭晫鐭╁艦涓嶆槸spinBox鐨勮竟鐣岀煩褰€?br style="word-break: break-all; line-height: normal; ">銆銆br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆r.height() - fw*2 );<br style="word-break: break-all; line-height: normal; ">銆銆p->fillRect( br, cg.brush( QColorGroup::Button ) );<br style="word-break: break-all; line-height: normal; ">銆銆int x = r.x(), y = r.y(), w = r.width(), h = r.height();<br style="word-break: break-all; line-height: normal; ">銆銆int sw = w-4;<br style="word-break: break-all; line-height: normal; ">銆銆int sh = sw/2 + 2;銆銆銆// Must have empty row at foot of arrow<br style="word-break: break-all; line-height: normal; ">銆銆int sx = x + w / 2 - sw / 2 - 1;<br style="word-break: break-all; line-height: normal; ">銆銆int sy = y + h / 2 - sh / 2 - 1;<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆QPointArray a;<br style="word-break: break-all; line-height: normal; ">銆銆/* 璁劇疆涓夎褰㈢殑涓変釜鐐圭殑鍧愭爣錛屼慨鏀硅繖涓変釜鐐瑰彲浠ヤ嬌寰桻SpinBox涓婃寜閽噷鐨勪笁瑙掑瀷鍛堢幇浠繪剰鐨勫艦鐘訛紝涓嬮潰鐨勮緗嬌寰椾笁瑙掑艦琛ㄧず鐨勭澶村垎鍒悜宸﹀拰鍚戝彸銆?/<br style="word-break: break-all; line-height: normal; ">銆銆if ( pe == PE_SpinWidgetDown )<br style="word-break: break-all; line-height: normal; ">銆銆銆銆a.setPoints( 3,銆0, sh/2,銆sw-1, 1,銆sw-1, sh-1 );<br style="word-break: break-all; line-height: normal; ">銆銆銆else<br style="word-break: break-all; line-height: normal; ">銆銆銆銆a.setPoints( 3,銆0, 1,銆0, sh-1,銆sw-1, sh/2 );<br style="word-break: break-all; line-height: normal; ">銆銆...........<br style="word-break: break-all; line-height: normal; ">銆銆p->drawPolygon( a );銆銆//緇樺埗涓夎褰?br style="word-break: break-all; line-height: normal; ">銆銆}else if((pe == PE_ButtonBevel) || (pe == PE_ButtonCommand) || (pe == PE_ButtonTool) || (pe == PE_ButtonDropDown) || (pe == PE_HeaderSection))<br style="word-break: break-all; line-height: normal; ">銆銆銆銆{ //緇樺埗鎸夐挳鐨勫悇縐嶆晥鏋滀嬌寰楃湅璧鋒潵鍑歌搗鎴栧嚬涓嬨?br style="word-break: break-all; line-height: normal; ">銆銆銆銆qDrawShadePanel(p, r, cg, flags & (Style_Sunken | Style_Down | Style_On), <br style="word-break: break-all; line-height: normal; ">銆銆1, &cg.brush(QColorGroup::Button));<br style="word-break: break-all; line-height: normal; ">銆銆銆銆}else{ <br style="word-break: break-all; line-height: normal; ">銆銆/*瀵逛簬鍏朵粬鍩烘湰鍥懼艦鍏冪礌(PrimitiveElement)鐨勭粯鍒舵垜浠笉浣滃鐞嗗彧鏄畝鍗曠殑璋冪敤鐖剁被鐨勫嚱鏁般?/<br style="word-break: break-all; line-height: normal; ">銆銆QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt);<br style="word-break: break-all; line-height: normal; ">銆銆銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆緇樺埗鏁翠釜spinBox鐨勫嚱鏁幫細<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆void CustomStyle::drawComplexControl( ComplexControl control,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 QPainter *p,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 const QWidget *widget,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 const QRect &r,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 const QColorGroup &cg,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 SFlags flags,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 SCFlags controls,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 SCFlags active,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆銆 const QStyleOption& opt ) const<br style="word-break: break-all; line-height: normal; ">銆銆{銆銆<br style="word-break: break-all; line-height: normal; ">銆銆//涓嬮潰鐨勪唬鐮佷嬌寰梥pinWidget鍛堢幇鍨傜洿鏄劇ず鐨勯鏍艱屼笉鏄氬父鐨勬按騫蟲樉紺?br style="word-break: break-all; line-height: normal; ">銆銆if (control == CC_SpinWidget) {<br style="word-break: break-all; line-height: normal; ">銆銆const QSpinWidget * sw = (const QSpinWidget *) widget;<br style="word-break: break-all; line-height: normal; ">銆銆//緇樺埗鍚戜笂鎸夐挳閮ㄥ垎錛宑ontrols榛樿涓篠C_All錛屽嵆緇樺埗鏁翠釜spinwidget<br style="word-break: break-all; line-height: normal; ">銆銆if ( controls & SC_SpinWidgetUp ) {<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆銆銆if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )<br style="word-break: break-all; line-height: normal; ">銆銆pe = PE_SpinWidgetPlus;銆// 浣跨敤鍔犲噺鍙楓<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452008145.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆銆銆else<br style="word-break: break-all; line-height: normal; ">銆銆pe" = PE_SpinWidgetUp;銆 // 浣跨敤涓夎褰€<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/200505261452007091.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; "><br style="word-break: break-all; line-height: normal; ">銆銆銆銆QRect" re = sw->upRect();<br style="word-break: break-all; line-height: normal; ">銆銆銆銆QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();<br style="word-break: break-all; line-height: normal; ">銆銆銆銆drawPrimitive(PE_ButtonBevel, p, re, ucg, flags); //緇樺埗鎸夐挳鐨勮竟妗?br style="word-break: break-all; line-height: normal; ">銆銆drawPrimitive(pe, p, re, ucg, flags); //緇樺埗鎸夐挳<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆//緇樺埗鍚戝乏鎸夐挳閮ㄥ垎銆?br style="word-break: break-all; line-height: normal; ">銆銆if ( controls & SC_SpinWidgetDown ) {<br style="word-break: break-all; line-height: normal; ">銆銆銆/*涓庣粯鍒跺悜涓嬫寜閽浉浼?/<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆}else{//涓嶅鐞唖pinbox涔嬪鐨勫叾浠栧鏉傛帶鍒墮儴浠訛紝璋冪敤鐖剁被鍑芥暟澶勭悊<br style="word-break: break-all; line-height: normal; ">銆銆QWindowsStyle::drawComplexControl(control, p, widget, r, cg, flags, controls, active, opt);<br style="word-break: break-all; line-height: normal; ">銆銆銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鑾峰彇閮ㄤ歡錛坵idget錛変腑鍚勪釜瀛愰儴浠跺竷灞淇℃伅鐨勫嚱鏁幫紝榪欎釜鍑芥暟鎺у埗鐫涓涓獁idget鐨勫瑙?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆QRect CustomStyle::querySubControlMetrics( ComplexControl control,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆const QWidget *widget,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆SubControl sc,<br style="word-break: break-all; line-height: normal; ">銆銆銆銆const QStyleOption &opt ) const<br style="word-break: break-all; line-height: normal; ">銆銆{<br style="word-break: break-all; line-height: normal; ">銆銆銆銆if(control == CC_SpinWidget){<br style="word-break: break-all; line-height: normal; ">銆銆銆銆int fw = pixelMetric( PM_SpinBoxFrameWidth, widget);<br style="word-break: break-all; line-height: normal; ">銆銆/*QSize 瀹氫箟浜岀淮瀵硅薄鐨勫ぇ灝?涔熷氨鏄鍜岄珮. 鍧愭爣綾誨瀷鏄疩COORD瀹氫箟涓篿nt)*/<br style="word-break: break-all; line-height: normal; ">銆銆QSize bs;銆//姝ゅbs琛ㄧず姣忎釜鎸夐挳鐨勫ぇ灝?鍥犱負鏈変袱涓寜閽墍浠ヤ笅闈㈤櫎浠?.<br style="word-break: break-all; line-height: normal; ">銆銆bs.setWidth(widget->width()/2 -fw);<br style="word-break: break-all; line-height: normal; ">銆銆if(bs.width() < 8) bs.setWidth(8);<br style="word-break: break-all; line-height: normal; ">銆銆/*鎸夐挳楂樺害璁劇疆涓篞MIN{鎸夐挳瀹藉害鐨?.6鍊? 閮ㄤ歡楂樺害鐨勫洓鍒嗕箣涓}<br style="word-break: break-all; line-height: normal; ">銆銆bs.setHeight(銆QMIN(bs.width()*8/5, widget->height() / 4) ); <br style="word-break: break-all; line-height: normal; ">銆銆bs = bs.expandedTo( QApplication::globalStrut() );<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆int x = fw;<br style="word-break: break-all; line-height: normal; ">銆銆int y, ly, ry;<br style="word-break: break-all; line-height: normal; ">銆銆y = widget->height() - x - bs.height();<br style="word-break: break-all; line-height: normal; ">銆銆ly = fw;<br style="word-break: break-all; line-height: normal; ">銆銆ry = y - fw;<br style="word-break: break-all; line-height: normal; ">銆銆//涓嬮潰瀹氫箟浜哘SpinWidget鐨勫悇涓瓙閮ㄤ歡鐨勫潗鏍囦綅緗?<br style="word-break: break-all; line-height: normal; ">銆銆switch ( sc ) {<br style="word-break: break-all; line-height: normal; ">銆銆case SC_SpinWidgetUp:<br style="word-break: break-all; line-height: normal; ">銆銆//榪斿洖鍚戝彸鎸夐挳鐨勫潗鏍囦俊鎭?br style="word-break: break-all; line-height: normal; ">銆銆銆銆return QRect(x + bs.width(), y, bs.width(), bs.height());<br style="word-break: break-all; line-height: normal; ">銆銆case SC_SpinWidgetDown:<br style="word-break: break-all; line-height: normal; ">銆銆//榪斿洖鍚戝乏鎸夐挳鐨勫潗鏍囦俊鎭?br style="word-break: break-all; line-height: normal; ">銆銆銆銆return QRect(x, y, bs.width(), bs.height());<br style="word-break: break-all; line-height: normal; ">銆銆case SC_SpinWidgetButtonField:<br style="word-break: break-all; line-height: normal; ">銆銆//榪斿洖涓や釜鎸夐挳鐨勬誨尯鍩熷ぇ灝?br style="word-break: break-all; line-height: normal; ">銆銆銆銆return QRect(x, y, widget->width() - 2*fw, bs.height());<br style="word-break: break-all; line-height: normal; ">銆銆case SC_SpinWidgetEditField:<br style="word-break: break-all; line-height: normal; ">銆銆/*榪斿洖鍙紪杈戞鐨勫潗鏍囦俊鎭?/<br style="word-break: break-all; line-height: normal; ">銆銆銆銆return QRect(fw, ly, widget->width() - 2*fw, ry);<br style="word-break: break-all; line-height: normal; ">銆銆case SC_SpinWidgetFrame:<br style="word-break: break-all; line-height: normal; ">銆銆//榪斿洖鏁翠釜spinBox鐨勫潗鏍囦俊鎭?br style="word-break: break-all; line-height: normal; ">銆銆銆銆return widget->rect();<br style="word-break: break-all; line-height: normal; ">銆銆default:<br style="word-break: break-all; line-height: normal; ">銆銆銆銆break;<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆銆銆}else{//鍏跺畠閮ㄤ歡鐨勫竷灞淇℃伅璋冪敤鐖剁被鐨勫嚱鏁版潵澶勭悊銆?br style="word-break: break-all; line-height: normal; ">銆銆return QWindowsStyle::querySubControlMetrics(control,widget,sc,opt );<br style="word-break: break-all; line-height: normal; ">銆銆銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆銆銆return QRect();<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<strong style="word-break: break-all; line-height: normal; ">3錛庝嬌鐢ㄦ柊椋庢牸</strong><br style="word-break: break-all; line-height: normal; ">銆銆鏈変袱縐嶆柟娉曚嬌鐢ㄦ柊椋庢牸錛屼竴縐嶆槸浣滀負鎻掍歡錛屼竴縐嶆槸鍦ㄥ簲鐢ㄧ▼搴忛噷鐩存帴浣跨敤銆備綔涓烘彃浠剁殑椋庢牸鍙互鍦ㄤ笉鐢ㄤ慨鏀逛唬鐮併佷笉鐢ㄩ噸鏂扮紪璇戠殑鎯呭喌涓嬩嬌鐢ㄦ柊椋庢牸銆傜敱浜庢湰鏂囩潃閲嶄粙緇嶅浣曞垱寤洪鏍兼墍浠ユ垜浠嬌鐢ㄧ涓縐嶆柟娉曘傝繖縐嶆柟娉曞緢綆鍗曪紝鍙渶鍦ㄥ簲鐢ㄧ▼搴忎腑鍖呭惈鐩稿簲椋庢牸綾葷殑澶存枃浠訛紝鐒跺悗鎶妋ain錛堬級鍑芥暟絎竴鍙ュ彲鎵ц浠g爜璁劇疆涓篞Application::setStyle(new MyStyle())鍗沖彲銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆涓嬮潰鎴戜滑鐢ㄤ竴涓皬渚嬪瓙鏉ョ湅鐪嬫晥鏋溿?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆#include <qapplication.h style="word-break: break-all; line-height: normal; "><br style="word-break: break-all; line-height: normal; ">銆銆#include <qspinbox.h style="word-break: break-all; line-height: normal; "><br style="word-break: break-all; line-height: normal; ">銆銆#include "customstyle.h"<br style="word-break: break-all; line-height: normal; ">銆銆int main( int argc, char **argv )<br style="word-break: break-all; line-height: normal; ">銆銆{<br style="word-break: break-all; line-height: normal; ">銆銆銆銆QApplication::setStyle(new CustomStyle()); //浣跨敤鏂伴鏍肩被鏉ョ粯鍒剁晫闈€?br style="word-break: break-all; line-height: normal; ">銆銆銆銆QApplication a( argc, argv );<br style="word-break: break-all; line-height: normal; ">銆銆銆銆QSpinBox spin( 0, 15 );<br style="word-break: break-all; line-height: normal; ">銆銆銆銆spin.resize( 20, 100 );<br style="word-break: break-all; line-height: normal; ">銆銆銆銆a.setMainWidget( &spin );<br style="word-break: break-all; line-height: normal; ">銆銆銆銆spin.show();<br style="word-break: break-all; line-height: normal; ">銆銆銆銆return a.exec();<br style="word-break: break-all; line-height: normal; ">銆銆}<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鐒跺悗緙栬瘧榪愯鍗沖彲鐪嬪埌鏁堟灉銆?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆Ps. qt涓紪璇戜嬌鐢╭make錛屾楠や負<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鍒涘緩婧愮▼搴?nbsp;<br style="word-break: break-all; line-height: normal; ">銆銆鍚屼竴鐩綍涓嬭繍琛宷make -project <br style="word-break: break-all; line-height: normal; ">銆銆qmake <br style="word-break: break-all; line-height: normal; ">銆銆make <br style="word-break: break-all; line-height: normal; ">銆銆榪愯鍙墽琛岀▼搴忋?nbsp;<br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆<strong style="word-break: break-all; line-height: normal; ">4錛庤繘涓姝ュ伐浣?/strong><br style="word-break: break-all; line-height: normal; ">銆銆1錛夐粯璁ゅぇ灝忥細緇嗗績鐨勬湅鍙嬪彲鑳界湅鍒頒笂闈㈢殑浠g爜涓湁涓鍙ワ細spin.resize( 20, 100 )錛岃繖涓鍙ヨ緗畇pinbox鐨勯暱搴︿負20璞$礌錛屽搴︿負100涓薄绱犮傚鏋滄病鏈夎繖涓鍙ョ殑璇濓紝鏄劇ず鐨勭粨鏋滀細涓鍥㈢碂錛屼袱涓寜閽嚑涔庣湅涓嶅埌<img src="http://www.chinaitpower.com/A-A-A/2005/05/26/20050526145200453.gif" onclick="javascript:window.open(this.src);" onload="return imgzoom(this,550)" title="鐐瑰嚮鍥劇墖鍙湪鏂扮獥鍙f墦寮" style="word-break: break-all; line-height: normal; max-width: 500px; cursor: pointer; ">錛屽洜涓簈t榛樿鐨勬樉紺烘槸姘村鉤鏄劇ず鑰屾牴鏈病鏈夎冭檻鍨傜洿鏄劇ず鐨勬儏鍐點?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆濡傛灉鎯寵spinbox鍦ㄩ粯璁ゆ儏鍐典笅鐪嬭搗鏉ラ暱搴︾獎鑰屽搴﹂珮闇瑕佷慨鏀筈SpinBox綾諱腑鐨剆izeHint鍑芥暟錛岃繖涓嚱鏁板姛鑳芥槸璁劇疆閮ㄤ歡(widget)鐨勯粯璁ゅ昂瀵搞傚湪qt涓嚑涔庢瘡涓狦UI閮ㄤ歡綾婚兘鏈塻izeHint榪欎釜鍑芥暟鏉ヨ緗畠鑷繁鐨勯粯璁ょ殑闀垮拰瀹姐?br style="word-break: break-all; line-height: normal; ">銆銆<br style="word-break: break-all; line-height: normal; ">銆銆鏂囨湰鍨傜洿鏄劇ず錛氬湪姝や緥涓櫧鐒舵帶浠秙pinbox杈懼埌浜嗗瀭鐩存樉紺虹殑鏁堟灉錛屼絾鏄枃鏈粛鏃ф槸姘村鉤鏄劇ず鐨勶紝鍥犳瑕佽揪鍒扮湡姝g殑鍨傜洿鏄劇ず闇瑕佷簡瑙t鐨勬枃鏈樉紺烘満鍒躲傝繖浜涘伐浣滄槸寰堟湁鎰忎箟鐨勶紝鍥犱負鏈変簺姘戞棌錛堝钂欐枃錛夌殑璇█浼犵粺灝辨槸鍨傜洿鏄劇ず鐨勶紝鑰岀幇鍦ㄦ病鏈変竴涓湡姝f弧瓚寵繖縐嶉渶姹傜殑緋葷粺銆傜瑪鑰呯幇鍦ㄦ鍦ㄧ湅qt-x11-free-3.2.2鐨勬簮鐮侊紝鐩墠瀵規枃鏈樉紺烘満鍒跺彧鏈夊垵姝ヤ簡瑙o紝榪樻病鏈夌湡姝e紕娓咃紝闈炲父甯屾湜鍜屾劅鍏磋叮鐨勬湅鍙嬬浉浜掍氦嫻併佸涔犮?</qspinbox.h></qapplication.h></span> <div><font color="#333333" face="Tahoma, Arial, Helvetica, snas-serif" size="4"><span style="font-size: 14px;"><br></span></font></div><div><font color="#333333" face="Tahoma, Arial, Helvetica, snas-serif" size="4"><span style="font-size: 14px;">杞嚜: http://www.lupaworld.com/?action-viewstutorial-itemid-7178</span></font></div><img src ="http://m.shnenglu.com/biao/aggbug/96081.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/biao/" target="_blank">鏆楅噾瑁呭</a> 2009-09-14 07:00 <a href="http://m.shnenglu.com/biao/archive/2009/09/14/96081.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>QtWidget: 鍒╃敤Qt4.5鏂扮壒鎬у疄鐜伴叿鐐忔槑紿椾綋http://m.shnenglu.com/biao/archive/2009/06/12/87508.html鏆楅噾瑁呭鏆楅噾瑁呭Fri, 12 Jun 2009 09:27:00 GMThttp://m.shnenglu.com/biao/archive/2009/06/12/87508.htmlhttp://m.shnenglu.com/biao/comments/87508.htmlhttp://m.shnenglu.com/biao/archive/2009/06/12/87508.html#Feedback5http://m.shnenglu.com/biao/comments/commentRss/87508.htmlhttp://m.shnenglu.com/biao/services/trackbacks/87508.html

Qt4.2寮曞叆浜?span style="color: rgb(0, 0, 128); ">QWidget::setWindowOpacity鍑芥暟錛?鍙互涓虹獥浣撹緗忔槑搴︼紝 浠?.0鍒?.0涔嬮棿錛?鍊艱秺灝忚秺閫忔槑銆?緇忚繃璁劇疆鐨勭獥浣撳彲浠ユ暣浣撳憟鐜伴忔槑鐨勬晥鏋溿?浣嗚繖縐嶈緗瘮杈冪矖緋欙紝 鍙兘璁句竴涓暣浣撶殑鏁堟灉錛?澶ф鍙湁姣斿鍍忔嫋鍔ㄧ殑鏃跺欒兘鐢ㄤ竴涓嬶紝 澶у鏁版椂鍊欓兘涓嶅お瀹炵敤銆?鍦≦t4.5閲屽紩鍏ヤ簡鏂扮殑紿椾綋閫忔槑鐗規э紝 鏄釜Widget鐨凙ttribute錛?鍙仛Qt::WA_TranslucentBackground銆?榪欎釜灞炴у彲浠ヤ負姣忎釜QWidget鍗曠嫭璁劇疆錛?騫朵笖閫忔槑紼嬪害鍙互鐢ㄧ粯鍒剁殑棰滆壊鎴栧浘鐗囩殑Alpha Channel鍊兼潵鎺у埗銆?/p>

絎旇呭啓浜嗕竴涓緥瀛愭紨紺哄叾濂囧鐨勬晥鏋溿?鍏堢湅涓涓埅鍥撅細
translucent

榪欎釜鏄瑪鑰呬緥瀛愯繍琛屽嚭鏉ョ殑鏁堟灉錛?鑳屾櫙鏄痺ww.cuteqt.com闆蜂漢鐨勪富欏點?nbsp; 涓嬮潰綆鍗曚粙緇嶄竴涓嬩唬鐮佺殑瀹炵幇銆?/p>

TranslucentBackground鎺у埗紿椾綋閫忔槑灞炴?/strong>
渚嬪瓙涓葷晫闈㈢敤QWidget錛?鍏朵笂鏀劇疆鍥涗釜鎺т歡錛?涓婇潰涓や釜鏄嚜瀹氫箟鐨凲Widget瀛愮被錛?鐢ㄥ湪paintEvent涓粯鍒朵簡涓騫呴忔槑搴曡壊鐨勫浘鐗囷紝 涓婁功“CuteQt”鍑犱釜澶у瓧錛?涓嬮潰涓や釜鏄爣鍑嗙殑QLabel鎺т歡錛?浣嗘樉紺哄嚭涓ょ涓嶅悓鐨勬晥鏋溿?/p>

閫忔槑鐨勬帶浠剁殑TranslucentBackground灞炴т負true 錛堢戶鎵夸簡parent鐨勫睘鎬э級錛?鑰岄潪閫忔槑鐨勬帶浠跺垯鍦ㄤ唬鐮佷腑寮哄埗灝員ranslucentBackground璁句負浜唂alse錛?榪欐牱灝遍犲氨浜嗘湁鎰忔濈殑緇撴灉銆?浠g爜鐗囨濡備笅錛?br>label = new QLabel(”www.cuteqt.com”);
label->setAttribute(Qt::WA_TranslucentBackground, false);
label->setAutoFillBackground(true);

Alpha Channel鎺у埗閫忔槑搴?/strong>
灝嗚繖涓緥瀛愮◢紼嶆敼鍔紝 淇敼涓涓嬬獥浣撹儗鏅壊鐨凙lpha鍊鹼紝 浣夸箣灞曠幇涓嶅悓鐨勯忔槑搴︺?瀹炵幇鐨勬柟娉曟槸璁劇疆紿椾綋鐨刾alette灞炴э紝 涓築ackground榪欎釜ColorRole鐨勯鑹茶緗簡alpha鍊鹼紝 浠g爜鐗囨濡備笅錛?br>QPalette pal = palette();
pal.setColor(QPalette::Background, QColor(255,0,0,200));
setPalette(pal);

涓嬪浘鎵紺轟負alpha鍊?00鍜?00鐨勪笉鍚屾樉紺烘晥鏋溿?/p>

translucent1

translucent2

鎬庝箞鏍鳳紝 榪欎釜渚嬪瓙鎸烘湁鎰忔濆惂錛?璧跺揩涓嬭澆瀹屾暣鐨勪唬鐮佸涔犱竴涓嬪惂锝?鏈変換浣曚笉鏄庣櫧blog鎴朾bs鐣欒█锝?/p>

translucent.tar.gz