разобрался на случаай если кому то понадобиться
void cell::addText(QString string,QRectF r){
text<<string;
rect<<r;
update();
}
void cell::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
for(int i=0;i<text.count();i++){
painter->drawRect(rect[i]);
QTextOption opt;
opt.setWrapMode(QTextOption::WrapAnywhere);
painter->drawText(rect[i],text[i],opt);
}
}
у меня еще одна проблема создал класс. он рисует сверху панель с днями недели и датой;
#include "week.h"
#include"QPainter"
#include"QStyleOptionButton"
#include "QStylePainter"
#include"QDate"
#include"QDebug"
week::week()
{
width=100;
numberOfWeek=0;
}
void week::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
QStylePainter p( widget );
QDate date;
int dayOfWeek=date.currentDate().dayOfWeek();
QStyleOptionButton monday,tuesday,wednesday,thursday,friday,saturday,sunday;
monday.initFrom(widget);
monday.state=QStyle::State_Raised | QStyle::State_Enabled;
monday.rect=QRect(0,0,width,30);
monday.text=(date.currentDate().addDays(1-dayOfWeek+numberOfWeek).toString());
tuesday.initFrom(widget);
tuesday.state=QStyle::State_Raised | QStyle::State_Enabled;
tuesday.rect=QRect(width,0,width,30);
tuesday.text=(date.currentDate().addDays(2-dayOfWeek+numberOfWeek).toString());
wednesday.initFrom(widget);
wednesday.state=QStyle::State_Raised | QStyle::State_Enabled;
wednesday.rect=QRect(width*2,0,width,30);
wednesday.text=(date.currentDate().addDays(3-dayOfWeek+numberOfWeek).toString());
thursday.initFrom(widget);
thursday.state=QStyle::State_Raised | QStyle::State_Enabled;
thursday.rect=QRect(width*3,0,width,30);
thursday.text=(date.currentDate().addDays(4-dayOfWeek+numberOfWeek).toString());
friday.initFrom(widget);
friday.state=QStyle::State_Raised | QStyle::State_Enabled;
friday.rect=QRect(width*4,0,width,30);
friday.text=(date.currentDate().addDays(5-dayOfWeek+numberOfWeek).toString());
saturday.initFrom(widget);
saturday.state=QStyle::State_Raised | QStyle::State_Enabled;
saturday.rect=QRect(width*5,0,width,30);
saturday.text=(date.currentDate().addDays(6-dayOfWeek+numberOfWeek).toString());
sunday.initFrom(widget);
sunday.state=QStyle::State_Raised | QStyle::State_Enabled;
sunday.rect=QRect(width*6,0,width,30);
sunday.text=(date.currentDate().addDays(7-dayOfWeek+numberOfWeek).toString());
p.drawControl(QStyle::CE_PushButton,monday);
p.drawControl(QStyle::CE_PushButton,tuesday);
p.drawControl(QStyle::CE_PushButton,wednesday);
p.drawControl(QStyle::CE_PushButton,thursday);
p.drawControl(QStyle::CE_PushButton,friday);
p.drawControl(QStyle::CE_PushButton,saturday);
p.drawControl(QStyle::CE_PushButton,sunday);
}
void week::nextWeek(){
numberOfWeek+=7;
qDebug()<<numberOfWeek;
update();
}
void week::previousWeek(){
numberOfWeek-=7;
qDebug()<<numberOfWeek;
update();
}
monday.text=(date.currentDate().addDays(1-dayOfWeek+numberOfWeek).toString())
1-понедельник(первый день недели)
dayOfWeek- нынешний день недели
numberOfWeek-номер недели начиная с этой*7(эта 0,следующая 1*7, предыдущая -1*7)
поидее при вызове функций nextWeek или previousWeek панель должна была перерисовываться с новыми значениями но не перерисовывается