Bonjour,
je veux colorer une case dans mon calendrier comme ds l'exemple (calendar de Qt examples and demos)
j'ai "réussi" à faire ça(copier coller),mais le problème est le suivant :
quand je veux colorer deux dates dans le même mois,les dates se dupliquent(de 1 à 30 apparaient deux fois) et ainsi de suite
void PlanningCourt::insert_calendar()
{
fontSize = 10;
editor->clear();
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
QDate date(selectedDate.year(), selectedDate.month(), 1);
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignHCenter);
tableFormat.setBackground(QColor("#e0e0e0"));
tableFormat.setCellPadding(1);
tableFormat.setCellSpacing(2);
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor.insertTable(1, 7, tableFormat);
QTextFrame *frame = cursor.currentFrame();
QTextFrameFormat frameFormat = frame->frameFormat();
frameFormat.setBorder(1);
frame->setFrameFormat(frameFormat);
QTextCharFormat format = cursor.charFormat();
format.setFontPointSize(fontSize);
QTextCharFormat boldFormat = format;
boldFormat.setFontWeight(QFont::Bold);
QTextCharFormat highlightedFormat = boldFormat;
highlightedFormat.setBackground(Qt::yellow);
for (int weekDay = 1; weekDay <= 7; ++weekDay)
{
QTextTableCell cell = table->cellAt(0, weekDay-1);
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
boldFormat);
}
table->insertRows(table->rows(), 1);
vector< string > vect_date;
vect_date=bd.select_date();
while (date.month() == selectedDate.month() ) {
int weekDay = date.dayOfWeek();
QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
QTextCursor cellCursor = cell.firstCursorPosition();
for(int i=0;i<vect_date.size();i++)//Içi c'est le problème,mais j'ai besoin de cette boucle pour parcourir les dates que je veux les colorer .
{
if (date.toString("dd/MM/yyyy") ==QString(vect_date[i].c_str()) )
cellCursor.insertText(date.toString("dd"), highlightedFormat);
else
cellCursor.insertText(QString("%1").arg(date.day()), format);
}
date = date.addDays(1);
if (weekDay == 7 && date.month() == selectedDate.month())
table->insertRows(table->rows(), 1);
}
cursor.endEditBlock();
setWindowTitle(tr("Calendar for %1 %2"
).arg(QDate::longMonthName(selectedDate.month())
).arg(selectedDate.year()));
}
merci pour votre aide.