Inicio

Glosario

Signals_Slots
Widget

Categorías del FAQ


Visitantes en linea:3
Visitantes de hoy:29
Total de visitantes:11987

Hay veces que se tiene la necesidad de marcar ciertos eventos en un calendar widget y Qt nos provee una forma muy fácil de hacerlo.

Esta clase de ejemplo aclara todo. Lo único que hago es extender QCalendarWidget y agregarle un método appendDate que marcará nuestros eventos( sacado del core de zmviewer ) Ademaś utilizo el método setDateTextFormat( const QDate & date, const QTextCharFormat & format ) de QCalendarWidget para setear el formato que quiera ( por ahora solo un background en amarillo y el texto subrayado )

class CameraEventCalendar : public QCalendarWidget{
public:
    CameraEventCalendar( QWidget * parent ): QCalendarWidget ( parent ){};
    void appendDate( const QDate & date ){
        QTextCharFormat fmt;
        fmt.setBackground( QBrush( Qt::yellow ) );
        fmt.setToolTip(tr("Click here to view events of this day"));
        fmt.setFontUnderline( true );
        setDateTextFormat( date , fmt );
        m_eventsDateList.append( date );
    }

    QList <QDate> eventsDateList() const{
        return m_eventsDateList;
    }
private:
    QList <QDate> m_eventsDateList;

};
 

Por lo que utilizar este widget sería tan sencillo como:

//instanciar
CameraEventCalendar * cameraEventsCalendar = new CameraEventCalendar( this );
// a modo de ejemplo instanciar un modelo
// que su fuente de datos es la tabla Events
QSqlTableModel * model = new QSqlTableModel ( this , QSqlDatabase::database () );
model->setTable ( "Events" );
model->select();
//recorrer el modelo y setear los eventos al calendario
for ( int i = 0 ; i < m_model->rowCount(); i++ ){
         cameraEventsCalendar->appendDate ( model->record( i ).value( "StartTime" ).toDate() );
    }

 

leo | Qt-src | 3 Julio, 4:39pm
Trackback URI: http://www.qtblog.com.ar/index.php?trackback/19
Parenting: Parenting / 16 Julio, 5:35pm
Mothers do the Parenting not the Parenting kids Parenting. You can get your parenting resource

Dejar un comentario









Fuentes XML de comentario: RSS | Atom

Amigos

KDE
LugOroVerde
Qt on Freenode
ggerman
Okular