![Qt基類翻譯-招募人員翻譯_第1頁](http://file4.renrendoc.com/view/f6f2340dc6ee9fe774643d6701ff9e3f/f6f2340dc6ee9fe774643d6701ff9e3f1.gif)
![Qt基類翻譯-招募人員翻譯_第2頁](http://file4.renrendoc.com/view/f6f2340dc6ee9fe774643d6701ff9e3f/f6f2340dc6ee9fe774643d6701ff9e3f2.gif)
![Qt基類翻譯-招募人員翻譯_第3頁](http://file4.renrendoc.com/view/f6f2340dc6ee9fe774643d6701ff9e3f/f6f2340dc6ee9fe774643d6701ff9e3f3.gif)
![Qt基類翻譯-招募人員翻譯_第4頁](http://file4.renrendoc.com/view/f6f2340dc6ee9fe774643d6701ff9e3f/f6f2340dc6ee9fe774643d6701ff9e3f4.gif)
![Qt基類翻譯-招募人員翻譯_第5頁](http://file4.renrendoc.com/view/f6f2340dc6ee9fe774643d6701ff9e3f/f6f2340dc6ee9fe774643d6701ff9e3f5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
QgraphicsItemQgraphicsItem是QGraphicsScene中全部項目的基類。對于自定義QGraphicsScene的項目,它供應(yīng)了重要的功能。包括項目的圖形集合,碰撞檢測,描繪實現(xiàn)(paintingimplementat(yī)ion),大事間的相互影響。QGraphicsItem是TheGraphicsView框架的一部分。Qt供應(yīng)大多數(shù)常用的圖形項目:QGraphicsEllipseItem供應(yīng)一個橢圓項目。QGraphicsLineItem供應(yīng)一個直線項目。QGraphicsPathItem供應(yīng)一個路徑項目。QGraphicsPixmapItem供應(yīng)一個位圖項目QGraphicsPolygonItem供應(yīng)一個區(qū)域項目QGraphicsRectItem供應(yīng)一個巨型項目QGraphicsTextItem供應(yīng)一個文本項目項目的全部圖形集合信息基于自己的坐標(biāo)系。項目的位置(pos()函數(shù))是唯一一個不基于自己的坐標(biāo)系的函數(shù),它使用它的父坐標(biāo)系(GraphicsView的坐標(biāo)系)。你可以使用setVisible()設(shè)置一個項目是否是可視的(也就是說畫和接受大事處理).隱藏一個項目,它的全部子項目也隱藏了.相同地,可以使用setEnabled().設(shè)置一個項目是否可用。一個項目不行用,它的全部子項目也不行用。選擇一個項目,首先設(shè)置ItemIsSelectable,標(biāo)記一個項目啟動選擇。然后調(diào)用setSelected()。通常,作為用戶交互的結(jié)果GraphicsScene被選擇.自己寫項目,須繼承QGraphicsItem,類。然后實現(xiàn)2個純虛方法boundingRect(),paint()。boundingRect()返回需要繪畫的區(qū)域。paint()實現(xiàn)繪畫。舉個例子:classSimpleItem:publicQGraphicsItem{public:QRectFboundingRect()const{qrealpenWidth=1;returnQRectF(-10-penWidth/2,—10—penWidth/2,20+penWidth/2,20+penWidth/2);}voidpaint(QPainter*painter,constQStyleOptionGraphicsItem*option,QWidget*widget){painter->drawRoundRect(-10,—10,20,20);}};TheboundingRect()functionhasmanydifferentpurposes。QGraphicsScenebasesitsitemindexonboundingRect(),andQGraphicsViewusesitbothforcullinginvisibleitems,andfordeterminingtheareathatneedstoberecomposedwhendrawingoverlappingitems.Inaddition,QGraphicsItem'scollisiondetectionmechanismsuseboundingRect()toprovideanefficientcut—off。ThefinegrainedcollisionalgorithmincollidesWithItem()isbasedoncallingshape(),whichreturnsanaccurateoutlineoftheitem'sshapeasaQPainterPat(yī)h.QGraphicsSceneexpectsallitemsboundingRect()andshape()toremainunchangedunlessitisnotified.Ifyouwanttochangeanitem’sgeometryinanyway,youmustfirstcallprepareGeometryChange()toallowQGraphicsScenetoupdateitsbookkeeping.Collisiondetectioncanbedoneintwoways:Reimplementshape()toreturnanaccurateshapeforyouritem,andrelyonthedefaultimplementationofcollidesWithItem()todoshape-shapeintersection。Thiscanberatherexpensiveiftheshapesarecomplex.ReimplementcollidesWithItem()toprovideyourowncustomitemandshapecollisionalgorithm.Thecontains()functioncanbecalledtodeterminewhethertheitemcontainsapointornot.Thisfunctioncanalsobereimplementedbytheitem.Thedefaultbehaviorofcontains()isbasedoncallingshape().Itemscancontainotheritems,andalsobecontainedbyotheritems.Allitemscanhaveaparentitemandalistofchildren。Unlesstheitemhasnoparent,itspositionisinparentcoordinates(i.e.,theparent'slocalcoordinates).Parentitemspropagateboththeirpositionandtheirtransformationtoallchildren。QGraphicsItemsupportsaffinetransformationsinadditiontoitsbaseposition,pos().Tochangetheitem'stransformation,youcaneitherpassatransformationmatrixtosetMat(yī)rix(),orcalloneoftheconveniencefunctionsrotate(),scale(),translate(),orshear()。Itemtransformat(yī)ionsaccumulatefromparenttochild,soifbothaparentandchilditemarerotat(yī)ed90degrees,thechild’stotaltransformationwillbe180degrees.Similarly,iftheitem’sparentisscaledto2xitsoriginalsize,itschildrenwillalsobetwiceaslarge.Anitem’stransformat(yī)iondoesnotaffectitsownlocalgeometry;allgeometryfunctions(e.g.,contains(),update(),andallthemappingfunctions)stilloperat(yī)einlocalcoordinates.Forconvenience,QGraphicsItemprovidesthefunctionssceneMatrix(),whichreturnstheitem'stotaltransformat(yī)ionmatrix(includingitspositionandallparents’positionsandtransformations),andscenePos(),whichreturnsitspositioninscenecoordinates.Toresetanitem'smatrix,callresetMatrix().Thepaint()functioniscalledbyQGraphicsViewtopainttheitem'scontents。Theitemhasnobackgroundordefaultfillofitsown;what(yī)everisbehindtheitemwillshinethroughallareasthat(yī)arenotexplicitlypaintedinthisfunction。Youcancallupdate()toschedulearepaint,optionallypassingtherectanglethatneedsarepaint。Dependingonwhetherornottheitemisvisibleinaview,theitemmayormaynotberepainted;thereisnoequivalenttoQWidget::repaint()inQGraphicsItem.Itemsarepaintedbytheview,startingwiththeparentitemsandthendrawingchildren,inascendingstackingorder。Youcansetanitem'sstackingorderbycallingsetZValue(),andtestitbycallingzValue(),whereitemswithlowz—valuesarepaintedbeforeitemswithhighz—values。Stackingorderappliestosiblingitems;parentsarealwaysdrawnbeforetheirchildren。QGraphicsItemreceiveseventsfromQGraphicsScenethroughthevirtualfunctionsceneEvent().Thisfunctiondistributesthemostcommoneventstoasetofconvenienceeventhandlers:contextMenuEvent()handlescontextmenueventsfocusInEvent()andfocusOutEvent()handlefocusinandouteventshoverEnterEvent(),hoverMoveEvent(),andhoverLeaveEvent()handleshoverenter,moveandleaveeventsinputMethodEvent()handlesinputevents,foraccessibilitysupportkeyPressEvent()andkeyReleaseEventhandlekeypressandreleaseeventsmousePressEvent(),mouseMoveEvent(),mouseReleaseEvent(),andmouseDoubleClickEvent()handlesmousepress,move,release,clickanddoubleclickeventsYoucanfiltereventsforanyotheritembyinstallingeventfilters.Thisfunctionalyisseparat(yī)efromfromQt'sregulareventfilters(seeQObject::installEventFilter()),whichonlyworkonsubclassesofQObject.AfterinstallingyouritemasaneventfilterforanotheritembycallinginstallSceneEventFilter(),thefilteredeventswillbereceivedbythevirtualfunctionsceneEventFilter().YoucanremoveitemeventfiltersbycallingremoveSceneEventFilter()。Sometimesit'susefultoregistercustomdatawithanitem,beitacustomitem,orastandarditem.YoucancallsetDat(yī)a()onanyitemtostoredat(yī)ainitusingakey—valuepair(thekeybeinganinteger,andthevalueisaQVariant)。Togetcustomdat(yī)afromanitem,calldata().ThisfunctionalityiscompletelyuntouchedbyQtitself;itisprovidedfortheuser'sconvenience。SeealsoQGraphicsScene,QGraphicsView,andTheGraphicsViewFramework.MemberTypeDocumentationenumQGraphicsItem::GraphicsItemChangeThisenumdescribesthestatechangesthatarenotifiedbyQGraphicsItem::itemChange().Thenotificat(yī)ionsaresentasthestatechanges,andinsomecases,adjustmentscanbemade(seethedocumentationforeachchangefordetails).Note:BecarefulwithcallingfunctionsontheQGraphicsItemitselfinsideitemChange(),ascertainfunctioncallscanleadtounwantedrecursion.Forexample,youcannotcallsetPos()initemChange()onanItemPositionChangenotification,asthesetPos()functionwillagaincallitemChange(ItemPositionChange).Instead,youcanreturnthenew,adjustedpositionfromitemChange().ConstantValueDescriptionQGraphicsItem::ItemEnabledChange3Theitem'senabledstatechanges.Iftheitemispresentlyenabled,itwillbecomedisabled,andviceverca.Thevalueargumentisthenewenabledstate(i。e。,trueorfalse).DonotcallsetEnabled()initemChange()asthisnotificat(yī)ionisdelivered.Instead,youcanreturnthenewstatefromitemChange().QGraphicsItem::ItemMatrixChange1Theitem'smat(yī)rixchanges.Thisnotificationisonlysentwhentheitem'slocalmatrixchanges(i.e.,asaresultofcallingsetMat(yī)rix(),oroneoftheconveniencetransformationfunctions,suchasrotate())。Thevalueargumentisthenewmat(yī)rix(i。e。,aQMatrix);togettheoldmatrix,callmatrix().DonotcallsetMatrix()oranyofthetransformationconveniencefunctionsinitemChange()asthisnotificationisdelivered;instead,youcanreturnthenewmat(yī)rixfromitemChange().QGraphicsItem::ItemPositionChange0Theitem’spositionchanges.Thisnotificationisonlysentwhentheitem’slocalpositionchanges,relativetoitsparent,haschanged(i.e.,asaresultofcallingsetPos()ormoveBy()).Thevalueargumentisthenewposition(i.e。,aQPointF)。Youcancallpos()togettheoriginalposition.DonotcallsetPos()ormoveBy()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenew,adjustedpositionfromitemChange().QGraphicsItem::ItemSelectedChange4Theitem'sselectedstat(yī)echanges。Iftheitemispresentlyselected,itwillbecomeunselected,andviceverca.Thevalueargumentisthenewselectedstate(i.e。,trueorfalse)。DonotcallsetSelected()initemChange()asthisnotificat(yī)ionisdelivered();instead,youcanreturnthenewselectedstatefromitemChange()。QGraphicsItem::ItemVisibleChange2Theitem'svisiblestat(yī)echanges.Iftheitemispresentlyvisible,itwillbecomeinvisible,andviceverca.Thevalueargumentisthenewvisiblestate(i。e.,trueorfalse).DonotcallsetVisible()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenewvisiblestatefromitemChange().QGraphicsItem::ItemParentChange5Theitem'sparentchanges.Thevalueargumentisthenewparentitem(i。e.,aQGraphicsItempointer).DonotcallsetParentItem()initemChange()asthisnotificat(yī)ionisdelivered;instead,youcanreturnthenewparentfromitemChange().QGraphicsItem::ItemChildAddedChange6Achildisaddedtothisitem.Thevalueargumentisthenewchilditem(i.e.,aQGraphicsItempointer).Donotpassthisitemtoanyitem'ssetParentItem()functionasthisnotificationisdelivered.Thereturnvalueisunused;youcannotadjustanythinginthisnotification。Notethatthenewchildmightnotbefullyconstructedwhenthisnotificationissent;callingpurevirtualfunctionsonthechildcanleadtoacrash.QGraphicsItem::ItemChildRemovedChange7Achildisremovedfromthisitem.Thevalueargumentisthechilditemthatisabouttoberemoved(i.e.,aQGraphicsItempointer)。Thereturnvalueisunused;youcannotadjustanythinginthisnotification。enumQGraphicsItem::GraphicsItemFlagflagsQGraphicsItem::GraphicsItemFlagsThisenumdescribesdifferentflagsthatyoucansetonanitemtotoggledifferentfeaturesintheitem'sbehavior.Allflagsaredisabledbydefault.ConstantValueDescriptionQGraphicsItem::ItemIsMovable0x1Theitemsupportsinteractivemovementusingthemouse.Byclickingontheitemandthendragging,theitemwillmovetogetherwiththemousecursor.Iftheitemhaschildren,allchildrenarealsomoved.Iftheitemispartofaselection,allselecteditemsarealsomoved。ThisfeatureisprovidedasaconveniencethroughthebaseimplementationofQGraphicsItem’smouseeventhandlers。QGraphicsItem::ItemIsSelectable0x2Theitemsupportsselection.EnablingthisfeaturewillenablesetSelected()totoggleselectionfortheitem.ItwillalsolettheitembeselectedautomaticallyasaresultofcallingQGraphicsScene::setSelectionA(yù)rea(),byclickingonanitem,orbyusingrubberbandselectioninQGraphicsView。QGraphicsItem::ItemIsFocusable0x4Theitemsupportskeyboardinputfocus(i.e.,itisaninputitem).Enablingthisflagwillallowtheitemtoacceptfocus,whichagainallowsthedeliveryofkeyeventstoQGraphicsItem::keyPressEvent()andQGraphicsItem::keyReleaseEvent().TheGraphicsItemFlagstypeisatypedefforQFlags〈GraphicsItemFlag>.ItstoresanORcombinationofGraphicsItemFlagvalues.MemberFunctionDocumentationQGraphicsItem::QGraphicsItem(QGraphicsItem*parent=0,QGraphicsScene*scene=0)ConstructsaQGraphicsItemwiththeparentparentonscene。Ifparentis0,theitemwillbeat(yī)op-level.Ifsceneis0,theitemwillnotbeassociatedwithascene.SeealsoQGraphicsScene::addItem()。QGraphicsItem::~QGraphicsItem()??[virtual]DestroystheQGraphicsItemandallitschildren.Ifthisitemiscurrentlyassociat(yī)edwithascene,theitemwillberemovedfromthescenebeforeitisdeleted.boolQGraphicsItem::acceptDrops()constReturnstrueifthisitemcanacceptdraganddropevents;otherwise,returnsfalse.Bydefault,itemsdonotacceptdraganddropevents;itemsaretransparenttodraganddrop.SeealsosetAcceptDrops()。Qt::MouseButtonsQGraphicsItem::acceptedMouseButtons()constReturnsthemousebuttonsthatthisitemacceptsmouseeventsfor.Bydefault,allmousebuttonsareaccepted.Ifanitemacceptsamousebutton,itwillbecomethemousegrabberitemwhenamousepresseventisdeliveredforthatmousebutton.However,iftheitemdoesnotacceptthebutton,QGraphicsScenewillforwardthemouseeventstothefirstitembeneathitthatdoes.SeealsosetAcceptedMouseButtons()andmousePressEvent().boolQGraphicsItem::acceptsHoverEvents()constReturnstrueifanitemacceptshoverevents(QGraphicsSceneHoverEvent);otherwise,returnsfalse.Bydefault,itemsdonotaccepthoverevents。SeealsosetAcceptsHoverEvents()andsetAcceptedMouseButtons().voidQGraphicsItem::advance(intphase)??[virtual]ThisvirtualfunctioniscalledtwiceforallitemsbytheQGraphicsScene::advance()slot.Inthefirstphase,allitemsarecalledwithphase==0,indicatingthatitemsonthesceneareabouttoadvance,andthenallitemsarecalledwithphase==1。Reimplementthisfunctiontoupdateyouritemifyouneedsimplescene—controlledanimation.Thedefaultimplementat(yī)iondoesnothing。Forindividualitemanimation,analternativetothisfunctionistoeitheruseQGraphicsItemAnimation,ortomultiple-inheritfromQObjectandQGraphicsItem,andanimateyouritemusingQObject::startTimer()andQObject::timerEvent().SeealsoQGraphicsItemAnimationandQTimeLine。QRectFQGraphicsItem::boundingRect()const??[purevirtual]Thispurevirtualfunctiondefinestheouterboundsoftheitemasarectangle;allpaintingmustberestrictedtoinsideanitem'sboundingrect.QGraphicsViewusesthistodeterminewhethertheitemrequiresredrawing。Althoughtheitem'sshapecanbearbitrary,theboundingrectisalwaysrectangular,anditisunaffectedbytheitems'transformation(scale(),rotate(),etc。)。Ifyouwanttochangetheitem’sboundingrectangle,youmustfirstcallprepareGeometryChange().Thisnotifiesthesceneoftheimminentchange,sothatitscanupdateitsitemgeometryindex;otherwise,thescenewillbeunawareoftheitem'snewgeometry,andtheresultsareundefined(typically,renderingartifactsareleftaroundintheview).ReimplementthisfunctiontoletQGraphicsViewdeterminewhatpartsofthewidget,ifany,needtoberedrawn.Note:Forshapesthatpaintanoutline/stroke,itisimportanttoincludehalfthepenwidthintheboundingrect.Itisnotnecessarypensat(yī)eforantialiasing,though.Example:QRectFCircleItem::boundingRect()const{qrealpenWidth=1;returnQRectF(-radius-penWidth/2,—radius—penWidth/2,diameter+penWidth,diameter+penWidth);}Seealsoshape(),contains(),TheGraphicsViewCoordinat(yī)eSystem,andprepareGeometryChange().QList<QGraphicsItem*〉QGraphicsItem::children()constReturnsalistofthisitem'schildren。Theitemsarereturnedinnoparticularorder.SeealsosetParentItem()。QRectFQGraphicsItem::childrenBoundingRect()constReturnstheboundingrectofthisitem'sdescendents(i。e.,itschildren,theirchildren,etc.)inlocalcoordinates.Iftheitemhasnochildren,thisfunctionreturnsanemptyQRectF.Thisdoesnotincludethisitem'sownboundingrect;itonlyreturnsitsdescendents'accumulatedboundingrect.Ifyouneedtoincludethisitem’sboundingrect,youcanaddboundingRect()tochildrenBoundingRect()usingQRectF::operator|()。Thisfunctionislinearincomplexity;itdeterminesthesizeofthereturnedboundingrectbyiteratingthroughalldescendents.SeealsoboundingRect()andsceneBoundingRect().voidQGraphicsItem::clearFocus()Takeskeyboardinputfocusfromtheitem。Ifithasfocus,afocusouteventissenttothisitemtotellitthatitisabouttolosethefocus。OnlyitemsthatsettheItemIsFocusableflagcanacceptkeyboardfocus.SeealsosetFocus()。boolQGraphicsItem::collidesWithItem(constQGraphicsItem*other,Qt::ItemSelectionModemode=Qt::IntersectsItemShape)const??[virtual]Returnstrueifthisitemcollideswithother;otherwisereturnsfalse。Thewaysitemscollideisdeterminedbymode.ThedefaultvalueformodeisQt::IntersectsItemShape;othercollideswiththisitemifiteitherintersectorarecontainedbythisitem'sshape.Thedefaultimplementationisbasedonshapeintersection,anditcallsshape()onbothitems.Becausethecomplexityofarbitraryshape-shapeintersectiongrowswithanorderofmagnitudewhentheshapesarecomplex,thisoperationcanbenoticablytimeconsuming.YouhavetheoptionofreimplementingthisfunctioninasubclassofQGraphicsItemtoprovideacustomalgorithm.Thisallowsyoutomakeuseofnaturalconstraintsintheshapesofyourownitems,inordertoimprovetheperformanceofthecollisiondetection.Forinstance,twountransformedperfectlycircularitems’collisioncanbedeterminedveryefficientlybycomparingtheirpositionsandradii.Keepinmindthatwhenreimplementingthisfunctionandcallingshape()orboundingRect()onother,thereturnedcoordinatesmustbemappedtothisitem’scoordinatesystembeforeanyintersectioncantakeplace。Seealsocontains()andshape()。boolQGraphicsItem::collidesWithPat(yī)h(constQPainterPat(yī)h&path,Qt::ItemSelectionModemode=Qt::IntersectsItemShape)const??[virtual]Returnstrueifthisitemcollideswithpath。Thecollisionisdeterminedbymode.ThedefaultvalueformodeisQt::IntersectsItemShape;pathcollideswiththisitemifiteitherintersectsoriscontainedbythisitem'sshape.SeealsocollidesWithItem(),contains(),andshape().QList<QGraphicsItem*〉QGraphicsItem::collidingItems(Qt::ItemSelectionModemode=Qt::IntersectsItemShape)constReturnsalistofallitemsthatcollidewiththisitem.Thewaycollisionsaredetectedisdeterminedbymode。ThedefaultvalueformodeisQt::IntersectsItemShape;Allitemswhoseshapeintersectsoriscontainedbythisitem'sshapearereturned.SeealsoQGraphicsScene::collidingItems()andcollidesWithItem().boolQGraphicsItem::contains(constQPointF&point)const??[virtual]Returnstrueifthisitemcontainspoint,whichisinlocalcoordinates;otherwise,falseisreturned.ItismostoftencalledfromQGraphicsViewtodeterminewhatitemisunderthecursor,andforthat(yī)reason,theimplementationofthisfunctionshouldbeaslight-weightaspossible。Bydefault,thisfunctioncallsshape(),butyoucanreimplementitinasubclasstoprovidea(perhapsmoreefficient)implementation.Seealsoshape(),boundingRect(),andcollidesWithPath()。voidQGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent*event)??[virtuat(yī)ected]Thiseventhandler,foreventevent,canbereimplementedtoreceivecontextmenueventsforthisitem.Ifyouignoretheevent,(i.e.,bycallingQEvent::ignore(),)eventwillpropagatetoanyitembeneaththisitem.Ifnoitemsaccepttheevent,itwillbeignoredbythescene,andpropagatetotheview.It'scommontoopenaQMenuinresponsetoreceivingacontextmenuevent。Example:voidCustomItem::contextMenuEvent(QGraphicsSceneContextMenuEvent*event){QMenumenu;QAction*removeAction=menu.a(chǎn)ddAction(”Remove");QAction*markAction=menu.addAction("Mark");QAction*selectedAction=menu.exec(event->screenPos());//...}Thedefaultimplementationdoesnothing.SeealsosceneEvent().QCursorQGraphicsItem::cursor()constReturnsthecurrentcursorshapefortheitem。Themousecursorwillassumethisshapewhenit’soverthisitem。Seethelistofpredefinedcursorobjectsforarangeofusefulshapes.AneditoritemmightwanttouseanI—beamcursor:item-〉setCursor(Qt::IBeamCursor);Ifnocursorhasbeenset,theparent’scursorisused。SeealsosetCursor(),hasCursor(),unsetCursor(),QWidget::cursor,andQApplication::overrideCursor()。QVariantQGraphicsItem::data(intkey)constReturnsthisitem'scustomdataforthekeykeyasaQVariant.Customitemdataisusefulforstoringarbitrarypropertiesinanyitem.Example:stat(yī)icconstintObjectName=0;QGraphicsItem*item=scene.itemAt(100,50);if(item—>data(ObjectName).toString()。isEmpty()){if(qgraphicsitem_cast<ButtonItem*〉(item))item-〉setData(ObjectName,"Button”);}Qtdoesnotusethisfeatureforstoringdata;itisprovidedsolelyfortheconvenienceoftheuser。SeealsosetDat(yī)a().voidQGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedragentereventsforthisitem。Dragentereventsaregeneratedasthecursorenterstheitem'sarea。Byacceptingtheevent,(i。e。,bycallingQEvent::accept(),)theitemwillacceptdropevents,inadditiontoreceivingdragmoveanddragleave.Otherwise,theeventwillbeignoredandpropagatetotheitembeneath。Iftheeventisaccepted,theitemwillreceiveadragmoveeventbeforecontrolgoesbacktotheeventloop.AcommonimplementationofdragEnterEventacceptsorignoreseventdependingontheassociat(yī)edmimedat(yī)ainevent.Example:CustomItem::CustomItem(){setAcceptDrops(true);.。.}voidCustomItem::dragEnterEvent(QGraphicsSceneDragDropEvent*event){event->setAccepted(event—〉mimeData()-〉hasFormat(yī)("text/plain"));}Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true).Thedefaultimplementationdoesnothing。SeealsodropEvent(),dragMoveEvent(),anddragLeaveEvent().voidQGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedragleaveeventsforthisitem。Dragleaveeventsaregeneratedasthecursorleavestheitem'sarea。Mostoftenyouwillnotneedtoreimplementthisfunction,butitcanbeusefulforresettingstat(yī)einyouritem(e.g.,highlighting).CallingQEvent::ignore()orQEvent::accept()oneventhasnoeffect.Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true).Thedefaultimplementationdoesnothing.SeealsodragEnterEvent(),dropEvent(),anddragMoveEvent().voidQGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedragmoveeventsforthisitem.Dragmoveeventsaregeneratedasthecursormovesaroundinsidetheitem'sarea.Mostoftenyouwillnotneedtoreimplementthisfunction;itisusedtoindicatethatonlypartsoftheitemcanacceptdrops.CallingQEvent::ignore()orQEvent::accept()oneventtoggleswhetherornottheitemwillacceptdropsatthepositionfromtheevent.Bydefault,eventisaccepted,indicat(yī)ingthat(yī)theitemallowsdropsat(yī)thespecifiedposition.Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true)。Thedefaultimplementat(yī)iondoesnothing.SeealsodropEvent(),dragEnterEvent(),anddragLeaveEvent().voidQGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent*event)??[virttected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedropeventsforthisitem.Itemscanonlyreceivedropeventsifthelastdragmoveeventwasaccepted.CallingQEvent::ignore()orQEvent::accept()oneventhasnoeffect。Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true)。Thedefaultimplementationdoesnothing.SeealsodragEnterEvent(),dragMoveEvent(),anddragLeaveEvent()。voidQGraphicsItem::ensureVisible(constQRectF&rect=QRectF(),intxmargin=50,intymargin=50)Ifthisitemispartofascenethat(yī)isviewedbyaQGraphicsView,thisconveniencefunctionwillattempttoscrolltheviewtoensurethatrectisvisibleinsidetheview'sviewport。Ifrectisanullrect(thedefault),QGraphicsItemwilldefaulttotheitem’sboundingrect.xmarginandymarginarethenumberofpixelstheviewshoulduseformargins。Ifthespecifiedrectcannotbereached,thecontentsarescrolledtothenearestvalidposition。IfthisitemisnotviewedbyaQGraphicsView,thisfunctiondoesnothing.SeealsoQGraphicsView::ensureVisible()。voidQGraphicsItem::ensureVisible(qrealx,qrealy,qrealw,qrealh,intxmargin=50,intymargin=50)Thisisanoverloadedmemberfunction,providedforconvenience.ThisconveniencefunctionisequivalenttocallingensureVisible(QRectF(x,y,w,h),xmargin,ymargin):GraphicsItemFlagsQGraphicsItem::flags()constReturnsthisitem’sflags。Theflagsdescribewhatconfigurablefeaturesoftheitemareenabledandnot.Forexample,iftheflagsincludeItemIsFocusable,theitemcanacceptinputfocus.Bydefault,noflagsareenabled.SeealsosetFlags()andsetFlag()。voidQGraphicsItem::focusInEvent(QFocusEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivefocusineventsforthisitem。Thedefaultimplementationdoesnothing。SeealsofocusOutEvent()andsceneEvent().voidQGraphicsItem::focusOutEvent(QFocusEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivefocusouteventsforthisitem.Thedefaultimplementationdoesnothing.SeealsofocusInEvent()andsceneEvent().QGraphicsItemGroup*QGraphicsItem::group()constReturnsapointertothisitem'sitemgroup,or0ifthisitemisnotmemberofagroup。SeealsosetGroup(),QGraphicsItemGroup,andQGraphicsScene::createItemGroup().boolQGraphicsItem::handlesChildEvents()constReturnstrueifthisitemhandleschildevents(i.e.,alleventsintendedforanyofitschildrenareinsteadsenttothisitem);otherwise,falseisreturned。Thispropertyisusefulforitemgroups;itallowsoneitemtohandleeventsonbehalfofitschildren,asopposedtoitschildrenhandlingtheireventsindividually.Thedefaultistoreturnfalse;childrenhandletheirownevents。TheexceptionforthisisiftheitemisaQGraphicsItemGroup,thenitdefaultstoreturntrue.SeealsosetHandlesChildEvents().boolQGraphicsItem::hasCursor()constReturnstrueifthisitemhasacursorset;otherwise,falseisreturned.Bydefault,itemsdon’thaveanycursorset.cursor()willreturnastandardpointingarrowcursor.SeealsounsetCursor()。boolQGraphicsItem::hasFocus()constReturnstrueifthisitemhasfocus(i。e.,canacceptkeyevents);otherwise,returnsfalse.SeealsosetFocus()andQGraphicsScene::setFocusItem().voidQGraphicsItem::hide()Hidestheitem。(Itemsarevisiblebydefault.)ThisconveniencefunctionisequivalenttocallingsetVisible(false).Seealsoshow()andsetVisible()。voidQGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivehoverentereventsforthi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中子、電子及Γ輻照裝置合作協(xié)議書
- 2025年機(jī)載設(shè)備綜合測試臺合作協(xié)議書
- 2025年石材翻新護(hù)理用品合作協(xié)議書
- 建筑力學(xué)期末考試B卷試題及答案
- 2025年個人貨物運輸協(xié)議模板(2篇)
- 2025年個人房屋設(shè)計裝修合同(4篇)
- 2025年五年級體育教師工作總結(jié)(5篇)
- 2025年儀器銷售合同標(biāo)準(zhǔn)版本(4篇)
- 2025年五年級語文備課組長工作總結(jié)范文(二篇)
- 2025年二手車車輛轉(zhuǎn)讓合同簡單版(2篇)
- DB43-T 2142-2021學(xué)校食堂建設(shè)與食品安全管理規(guī)范
- 宏觀利率篇:債券市場研究分析框架
- 橋梁頂升移位改造技術(shù)規(guī)范
- 六年級語文(上冊)選擇題集錦
- 介紹人提成方案
- 天津在津居住情況承諾書
- PHOTOSHOP教案 學(xué)習(xí)資料
- 初中數(shù)學(xué)教學(xué)“教-學(xué)-評”一體化研究
- 2012年安徽高考理綜試卷及答案-文檔
- 《游戲界面設(shè)計專題實踐》課件-知識點5:圖標(biāo)繪制準(zhǔn)備與繪制步驟
- 自動扶梯安裝過程記錄
評論
0/150
提交評論