版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
QgraphicsItemQgraphicsItem是QGraphicsScene中全部项目的基类。对于自定义QGraphicsScene的项目,它供应了重要的功能。包括项目的图形集合,碰撞检测,描绘实现(paintingimplementation),大事间的相互影响。QGraphicsItem是TheGraphicsView框架的一部分。Qt供应大多数常用的图形项目:QGraphicsEllipseItem供应一个椭圆项目。QGraphicsLineItem供应一个直线项目。QGraphicsPathItem供应一个路径项目。QGraphicsPixmapItem供应一个位图项目QGraphicsPolygonItem供应一个区域项目QGraphicsRectItem供应一个巨型项目QGraphicsTextItem供应一个文本项目项目的全部图形集合信息基于自己的坐标系。项目的位置(pos()函数)是唯一一个不基于自己的坐标系的函数,它使用它的父坐标系(GraphicsView的坐标系)。你可以使用setVisible()设置一个项目是否是可视的(也就是说画和接受大事处理).隐藏一个项目,它的全部子项目也隐藏了.相同地,可以使用setEnabled().设置一个项目是否可用。一个项目不行用,它的全部子项目也不行用。选择一个项目,首先设置ItemIsSelectable,标记一个项目启动选择。然后调用setSelected()。通常,作为用户交互的结果GraphicsScene被选择.自己写项目,须继承QGraphicsItem,类。然后实现2个纯虚方法boundingRect(),paint()。boundingRect()返回需要绘画的区域。paint()实现绘画。举个例子: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'sshapeasaQPainterPath.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,youcaneitherpassatransformationmatrixtosetMatrix(),orcalloneoftheconveniencefunctionsrotate(),scale(),translate(),orshear()。Itemtransformationsaccumulatefromparenttochild,soifbothaparentandchilditemarerotated90degrees,thechild’stotaltransformationwillbe180degrees.Similarly,iftheitem’sparentisscaledto2xitsoriginalsize,itschildrenwillalsobetwiceaslarge.Anitem’stransformationdoesnotaffectitsownlocalgeometry;allgeometryfunctions(e.g.,contains(),update(),andallthemappingfunctions)stilloperateinlocalcoordinates.Forconvenience,QGraphicsItemprovidesthefunctionssceneMatrix(),whichreturnstheitem'stotaltransformationmatrix(includingitspositionandallparents’positionsandtransformations),andscenePos(),whichreturnsitspositioninscenecoordinates.Toresetanitem'smatrix,callresetMatrix().Thepaint()functioniscalledbyQGraphicsViewtopainttheitem'scontents。Theitemhasnobackgroundordefaultfillofitsown;whateverisbehindtheitemwillshinethroughallareasthatarenotexplicitlypaintedinthisfunction。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.ThisfunctionalyisseparatefromfromQt'sregulareventfilters(seeQObject::installEventFilter()),whichonlyworkonsubclassesofQObject.AfterinstallingyouritemasaneventfilterforanotheritembycallinginstallSceneEventFilter(),thefilteredeventswillbereceivedbythevirtualfunctionsceneEventFilter().YoucanremoveitemeventfiltersbycallingremoveSceneEventFilter()。Sometimesit'susefultoregistercustomdatawithanitem,beitacustomitem,orastandarditem.YoucancallsetData()onanyitemtostoredatainitusingakey—valuepair(thekeybeinganinteger,andthevalueisaQVariant)。Togetcustomdatafromanitem,calldata().ThisfunctionalityiscompletelyuntouchedbyQtitself;itisprovidedfortheuser'sconvenience。SeealsoQGraphicsScene,QGraphicsView,andTheGraphicsViewFramework.MemberTypeDocumentationenumQGraphicsItem::GraphicsItemChangeThisenumdescribesthestatechangesthatarenotifiedbyQGraphicsItem::itemChange().Thenotificationsaresentasthestatechanges,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()asthisnotificationisdelivered.Instead,youcanreturnthenewstatefromitemChange().QGraphicsItem::ItemMatrixChange1Theitem'smatrixchanges.Thisnotificationisonlysentwhentheitem'slocalmatrixchanges(i.e.,asaresultofcallingsetMatrix(),oroneoftheconveniencetransformationfunctions,suchasrotate())。Thevalueargumentisthenewmatrix(i。e。,aQMatrix);togettheoldmatrix,callmatrix().DonotcallsetMatrix()oranyofthetransformationconveniencefunctionsinitemChange()asthisnotificationisdelivered;instead,youcanreturnthenewmatrixfromitemChange().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'sselectedstatechanges。Iftheitemispresentlyselected,itwillbecomeunselected,andviceverca.Thevalueargumentisthenewselectedstate(i.e。,trueorfalse)。DonotcallsetSelected()initemChange()asthisnotificationisdelivered();instead,youcanreturnthenewselectedstatefromitemChange()。QGraphicsItem::ItemVisibleChange2Theitem'svisiblestatechanges.Iftheitemispresentlyvisible,itwillbecomeinvisible,andviceverca.Thevalueargumentisthenewvisiblestate(i。e.,trueorfalse).DonotcallsetVisible()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenewvisiblestatefromitemChange().QGraphicsItem::ItemParentChange5Theitem'sparentchanges.Thevalueargumentisthenewparentitem(i。e.,aQGraphicsItempointer).DonotcallsetParentItem()initemChange()asthisnotificationisdelivered;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::setSelectionArea(),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,theitemwillbeatop-level.Ifsceneis0,theitemwillnotbeassociatedwithascene.SeealsoQGraphicsScene::addItem()。QGraphicsItem::~QGraphicsItem()??[virtual]DestroystheQGraphicsItemandallitschildren.Ifthisitemiscurrentlyassociatedwithascene,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.Thedefaultimplementationdoesnothing。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.Itisnotnecessarypensateforantialiasing,though.Example:QRectFCircleItem::boundingRect()const{qrealpenWidth=1;returnQRectF(-radius-penWidth/2,—radius—penWidth/2,diameter+penWidth,diameter+penWidth);}Seealsoshape(),contains(),TheGraphicsViewCoordinateSystem,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::collidesWithPath(constQPainterPath&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,andforthatreason,theimplementationofthisfunctionshouldbeaslight-weightaspossible。Bydefault,thisfunctioncallsshape(),butyoucanreimplementitinasubclasstoprovidea(perhapsmoreefficient)implementation.Seealsoshape(),boundingRect(),andcollidesWithPath()。voidQGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent*event)??[virtuatected]Thiseventhandler,foreventevent,canbereimplementedtoreceivecontextmenueventsforthisitem.Ifyouignoretheevent,(i.e.,bycallingQEvent::ignore(),)eventwillpropagatetoanyitembeneaththisitem.Ifnoitemsaccepttheevent,itwillbeignoredbythescene,andpropagatetotheview.It'scommontoopenaQMenuinresponsetoreceivingacontextmenuevent。Example:voidCustomItem::contextMenuEvent(QGraphicsSceneContextMenuEvent*event){QMenumenu;QAction*removeAction=menu.addAction(”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:staticconstintObjectName=0;QGraphicsItem*item=scene.itemAt(100,50);if(item—>data(ObjectName).toString()。isEmpty()){if(qgraphicsitem_cast<ButtonItem*〉(item))item-〉setData(ObjectName,"Button”);}Qtdoesnotusethisfeatureforstoringdata;itisprovidedsolelyfortheconvenienceoftheuser。SeealsosetData().voidQGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedragentereventsforthisitem。Dragentereventsaregeneratedasthecursorenterstheitem'sarea。Byacceptingtheevent,(i。e。,bycallingQEvent::accept(),)theitemwillacceptdropevents,inadditiontoreceivingdragmoveanddragleave.Otherwise,theeventwillbeignoredandpropagatetotheitembeneath。Iftheeventisaccepted,theitemwillreceiveadragmoveeventbeforecontrolgoesbacktotheeventloop.AcommonimplementationofdragEnterEventacceptsorignoreseventdependingontheassociatedmimedatainevent.Example:CustomItem::CustomItem(){setAcceptDrops(true);.。.}voidCustomItem::dragEnterEvent(QGraphicsSceneDragDropEvent*event){event->setAccepted(event—〉mimeData()-〉hasFormat("text/plain"));}Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true).Thedefaultimplementationdoesnothing。SeealsodropEvent(),dragMoveEvent(),anddragLeaveEvent().voidQGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent*event)??[virtualprotected]Thiseventhandler,foreventevent,canbereimplementedtoreceivedragleaveeventsforthisitem。Dragleaveeventsaregeneratedasthecursorleavestheitem'sarea。Mostoftenyouwillnotneedtoreimplementthisfunction,butitcanbeusefulforresettingstateinyouritem(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,indicatingthattheitemallowsdropsatthespecifiedposition.Itemsdonotreceivedraganddropeventsbydefault;toenablethisfeature,callsetAcceptDrops(true)。Thedefaultimplementationdoesnothing.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)IfthisitemispartofascenethatisviewedbyaQGraphicsView,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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辽宁石化职业技术学院《审计流程实验》2023-2024学年第一学期期末试卷
- 昆明幼儿师范高等专科学校《社会科学名著》2023-2024学年第一学期期末试卷
- 江西传媒职业学院《机械制造技术基础实验》2023-2024学年第一学期期末试卷
- 吉林师范大学博达学院《课外读写实践》2023-2024学年第一学期期末试卷
- 湖南商务职业技术学院《电子线路CAD设计》2023-2024学年第一学期期末试卷
- 湖南财政经济学院《中国民族民间舞(一)》2023-2024学年第一学期期末试卷
- 黑龙江三江美术职业学院《中文工具书》2023-2024学年第一学期期末试卷
- 重庆工业职业技术学院《经济地理学》2023-2024学年第一学期期末试卷
- 浙江科技学院《材料综合实验》2023-2024学年第一学期期末试卷
- 年产2万吨盐酸二甲双胍原料药项目可行性研究报告模板-立项备案
- 病例报告表(CRF)模板
- 2024年重庆市中考数学试卷(AB合卷)【附答案】
- 2024届高考语文作文备考:立足材料打造分论点 教学设计
- 幼儿园大班数学练习题100道及答案解析
- 对讲机外壳注射模设计 模具设计及制作专业
- 2024年四川省德阳市中考道德与法治试卷(含答案逐题解析)
- 施工现场水电费协议
- SH/T 3046-2024 石油化工立式圆筒形钢制焊接储罐设计规范(正式版)
- 六年级数学质量分析及改进措施
- 一年级下册数学口算题卡打印
- 【阅读提升】部编版语文五年级下册第三单元阅读要素解析 类文阅读课外阅读过关(含答案)
评论
0/150
提交评论