Qt基类翻译招募人员翻译.docx
- 文档编号:8727256
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:44
- 大小:39.69KB
Qt基类翻译招募人员翻译.docx
《Qt基类翻译招募人员翻译.docx》由会员分享,可在线阅读,更多相关《Qt基类翻译招募人员翻译.docx(44页珍藏版)》请在冰豆网上搜索。
Qt基类翻译招募人员翻译
QgraphicsItem
QgraphicsItem是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:
1.Reimplementshape()toreturnanaccurateshapeforyouritem,andrelyonthedefaultimplementationofcollidesWithItem()todoshape-shapeintersection.Thiscanberatherexpensiveiftheshapesarecomplex.
2.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()handlescontextmenuevents
*focusInEvent()andfocusOutEvent()handlefocusinandoutevents
*hoverEnterEvent(),hoverMoveEvent(),andhoverLeaveEvent()handleshoverenter,moveandleaveevents
*inputMethodEvent()handlesinputevents,foraccessibilitysupport
*keyPressEvent()andkeyReleaseEventhandlekeypressandreleaseevents
*mousePressEvent(),mouseMoveEvent(),mouseReleaseEvent(),andmouseDoubleClickEvent()handlesmousepress,move,release,clickanddoubleclickevents
Youcanfiltereventsforanyotheritembyinstallingeventfilters.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.
MemberTypeDocumentation
enumQGraphicsItem:
:
GraphicsItemChange
ThisenumdescribesthestatechangesthatarenotifiedbyQGraphicsItem:
:
itemChange().Thenotificationsaresentasthestatechanges,andinsomecases,adjustmentscanbemade(seethedocumentationforeachchangefordetails).
Note:
BecarefulwithcallingfunctionsontheQGraphicsItemitselfinsideitemChange(),ascertainfunctioncallscanleadtounwantedrecursion.Forexample,youcannotcallsetPos()initemChange()onanItemPositionChangenotification,asthesetPos()functionwillagaincallitemChange(ItemPositionChange).Instead,youcanreturnthenew,adjustedpositionfromitemChange().
Constant
Value
Description
QGraphicsItem:
:
ItemEnabledChange
3
Theitem'senabledstatechanges.Iftheitemispresentlyenabled,itwillbecomedisabled,andviceverca.Thevalueargumentisthenewenabledstate(i.e.,trueorfalse).DonotcallsetEnabled()initemChange()asthisnotificationisdelivered.Instead,youcanreturnthenewstatefromitemChange().
QGraphicsItem:
:
ItemMatrixChange
1
Theitem'smatrixchanges.Thisnotificationisonlysentwhentheitem'slocalmatrixchanges(i.e.,asaresultofcallingsetMatrix(),oroneoftheconveniencetransformationfunctions,suchasrotate()).Thevalueargumentisthenewmatrix(i.e.,aQMatrix);togettheoldmatrix,callmatrix().DonotcallsetMatrix()oranyofthetransformationconveniencefunctionsinitemChange()asthisnotificationisdelivered;instead,youcanreturnthenewmatrixfromitemChange().
QGraphicsItem:
:
ItemPositionChange
0
Theitem'spositionchanges.Thisnotificationisonlysentwhentheitem'slocalpositionchanges,relativetoitsparent,haschanged(i.e.,asaresultofcallingsetPos()ormoveBy()).Thevalueargumentisthenewposition(i.e.,aQPointF).Youcancallpos()togettheoriginalposition.DonotcallsetPos()ormoveBy()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenew,adjustedpositionfromitemChange().
QGraphicsItem:
:
ItemSelectedChange
4
Theitem'sselectedstatechanges.Iftheitemispresentlyselected,itwillbecomeunselected,andviceverca.Thevalueargumentisthenewselectedstate(i.e.,trueorfalse).DonotcallsetSelected()initemChange()asthisnotificationisdelivered();instead,youcanreturnthenewselectedstatefromitemChange().
QGraphicsItem:
:
ItemVisibleChange
2
Theitem'svisiblestatechanges.Iftheitemispresentlyvisible,itwillbecomeinvisible,andviceverca.Thevalueargumentisthenewvisiblestate(i.e.,trueorfalse).DonotcallsetVisible()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenewvisiblestatefromitemChange().
QGraphicsItem:
:
ItemParentChange
5
Theitem'sparentchanges.Thevalueargumentisthenewparentitem(i.e.,aQGraphicsItempointer).DonotcallsetParentItem()initemChange()asthisnotificationisdelivered;instead,youcanreturnthenewparentfromitemChange().
QGraphicsItem:
:
ItemChildAddedChange
6
Achildisaddedtothisitem.Thevalueargumentisthenewchilditem(i.e.,aQGraphicsItempointer).Donotpassthisitemtoanyitem'ssetParentItem()functionasthisnotificationisdelivered.Thereturnvalueisunused;youcannotadjustanythinginthisnotification.Notethatthenewchildmightnotbefullyconstructedwhenthisnotificationissent;callingpurevirtualfunctionsonthechildcanleadtoacrash.
QGraphicsItem:
:
ItemChildRemovedChange
7
A
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Qt 翻译 招募 人员