2012年3月24日星期六

Beats By DreWe oftendo some form display information

We oftendo some form display information ,which frequently have the date and time information .When using Qt Model / View, if you use view with delegate ,UGG Sale UK,shows the time may not be able to meet the requirements .
This requires us to write a new class delegate .The following is a specifically for the show date and time of the class delegate &ldquo ;TimeEditDelegate&rdquo ;Qt ,from Wiki ,I changed .The.
H file # ifndef TIMEEDITDELEGATE_H define TIMEEDITDELEGATE_H # # include < ;QItemDelegate> ;class TimeEditDelegate :public QItemDelegate {Q_OBJECTpublic: TimeEditDelegate ( const QString timeFormat = " ;dd.
MM.yyyy HH: mm: ss" ;QObject * ,parent = 0 ) :QItemDelegate ( parent ) {this-> ;timeformat = timeFormat ;} ;void paint ( QPainter * painter ,const QStyleOptionViewItem & ;const QModelIndex & ;option ,Beats By Dre,index ) const ;private : QString timeformat ;} ;# ENDIF / / TIMEEDITDELEGATE_H.
Cpp file # include " ;timeeditdelegate.h" ;include < QModelIndex> ;# # ;include < ;QPainter> ;include < QDateTime> ;# # ;include < ;QStyleOptionViewItemV3> include < ;# ;QStyleOptionViewItemV2> ;void TimeEditDelegate: :paint ( QPainter * painter ,const QStyleOptionViewItem & ;const QModelIndex & ;option ,index ) const {QDateTime dtval = index.
model > ( ) ;data ( index ,Qt: :DisplayRole ) . ToDateTime ( ) ;QString indexvalue = tr ( " ;Date not set" ;if ) ;( dtval.isVali D ( ) ) {indexvalue = dtval.toString ( timeformat ) ;} Q_ASSERT ( index.
isValid ( ) ) ;QStyleOptionViewItemV3 opt = setOptions ( index ,option ) ;const QStyleOptionViewItemV2 * V2 = qstyleoption_cast< ;const QStyleOptionViewItemV2 * > ;( & ;option ) ;opt.
features = V2 ?V2-> ;features :QStyleOptionViewItemV2: :ViewItemFeatures ( QStyleOptionViewItemV2: :None ) ;const QStyleOptionViewItemV3 * V3 = qstyleoption_cast< ;const QStyleOptionViewItemV3 * > ;( & ;option ) ;opt.
locale = V3 ?V3-> ;locale :QLocale ( ) ;opt.widget = V3 ?V3-> ;widget :0 ;/ / prepare painter-> ;save ( ) ;painter-> ;setClipRect ( opt.rect ) ;/ / get the data and the rectangles QVariant value ;QPixmap pixmap ;QRect decorationRect ;value = index.
data ( Qt: :DecorationRole ) ;QString text ;QRect displayRect ;value = index.data ( Qt: :DisplayRole ) ;if ( value.isValid ( ) ) {text = indexvalue ;displayRect = textRectangle ( painter ,option.
rect ,opt.font ,Moncler Online,text ) ;} QRe CT checkRect ;Qt: :CheckState checkState = Qt: :Unchecked ;value = index.data ( Qt: :CheckStateRole ) ;if ( value.isValid ( ) ) {checkState = static_cast< ;Qt: CheckState> ;( value.
toInt ( ) ) ;checkRect = check ( OPT ,opt.rect ,UGG Sale,value ) ;} / / do the layout doLayout ( opt ,& ;checkRect ,Beats Headphones,& ;decorationRect ,& ;displayRect ,false ) ;/ / draw the item drawBackground ( painter ,opt ,index ) ;drawCheck ( painter ,opt ,checkRect ,checkState ) ;drawDecoration ( painter ,opt ,decorationRect ,pixmap ) ;drawDisplay ( painter ,opt ,displayRect ,text ) ;drawFocus ( painter ,opt ,displayRect ) ;/ / done painter-> ;restore ( ) ;} setItemDelegateForColumn ( C use View-> ;TimeEditDelegate ,new ( " ;yyyy-dd-MM" ;) ) ;wherein ,C is needed to show the date and time of the column number .
Related articles:

没有评论:

发表评论