{
ui->setupUi(this);
selectedDate
=QDate::currentDate();
x=selectedDate.month();
// QString style="QPushButton::forwardBut { width:26px; height:17px;"
// "image: url(icons:right_arrow.png); } ";
int count=1,i,j;
MonthLbl
=new QLabel("MonthDisplay");
MonthLbl->setText(selectedDate.longMonthName(x));;
forwardBut
->setIcon
(QIcon("C:/Plackal/QtWorkspace/CustomCalender/Images/back-icon.PNG"));
for(i=1;i<=7;i++)
{
weekLbl
[i
]=new QLabel(selectedDate.
shortDayName(i
));
hWeek->addWidget(weekLbl[i],1,i);
}
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(count<=42)
{
controlsLayout->addWidget(button[i][j], i, j);
count++;
}
}
}
controlsLayout->setMargin(0);
controlsLayout->setHorizontalSpacing(0);
controlsLayout->setVerticalSpacing(0);
h->addWidget(backwardBut);
h->addWidget(blank);
h->addWidget(MonthLbl);
h->addWidget(blank);
h->addWidget(forwardBut);
hLbl->addWidget(blankLbl);
v->addLayout(h);
v->addLayout(hLbl);
v->addLayout(hWeek);
v->addLayout(controlsLayout);
v->addWidget(txtDate);
//centralWidget->setLayout(controlsLayout);
centralWidget->setLayout(v);
setCentralWidget(centralWidget);
connect(forwardBut,SIGNAL(clicked()),this,SLOT(monthForward()));
connect(backwardBut,SIGNAL(clicked()),this,SLOT(monthBackward()));
}
void MainWindow::monthForward()
{
MonthLbl->setText(selectedDate.longMonthName(++x));
if(x>12)
x=1;
}
void MainWindow::monthBackward()
{
MonthLbl->setText(selectedDate.longMonthName(--x));
if(x<2)
x=13;
}
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget *centralWidget = new QWidget;
selectedDate=QDate::currentDate();
x=selectedDate.month();
// QString style="QPushButton::forwardBut { width:26px; height:17px;"
// "image: url(icons:right_arrow.png); } ";
int count=1,i,j;
MonthLbl=new QLabel("MonthDisplay");
MonthLbl->setText(selectedDate.longMonthName(x));;
QPushButton *button[10][10],*forwardBut,*backwardBut;
forwardBut=new QPushButton();
forwardBut->setIcon(QIcon("C:/Plackal/QtWorkspace/CustomCalender/Images/back-icon.PNG"));
backwardBut=new QPushButton("<-");
QGridLayout *controlsLayout = new QGridLayout;
QGridLayout *hWeek = new QGridLayout;
QVBoxLayout *v=new QVBoxLayout;
QHBoxLayout *h=new QHBoxLayout;
QHBoxLayout *hLbl=new QHBoxLayout;
QLabel *blankLbl=new QLabel;
QLabel *blank=new QLabel;
QLabel *weekLbl[7];
for(i=1;i<=7;i++)
{
weekLbl[i]=new QLabel(selectedDate.shortDayName(i));
hWeek->addWidget(weekLbl[i],1,i);
}
QTextBrowser *txtDate=new QTextBrowser;
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(count<=42)
{
button[i][j] = new QPushButton(QString::number(count));
controlsLayout->addWidget(button[i][j], i, j);
count++;
}
}
}
controlsLayout->setMargin(0);
controlsLayout->setHorizontalSpacing(0);
controlsLayout->setVerticalSpacing(0);
h->addWidget(backwardBut);
h->addWidget(blank);
h->addWidget(MonthLbl);
h->addWidget(blank);
h->addWidget(forwardBut);
hLbl->addWidget(blankLbl);
v->addLayout(h);
v->addLayout(hLbl);
v->addLayout(hWeek);
v->addLayout(controlsLayout);
v->addWidget(txtDate);
//centralWidget->setLayout(controlsLayout);
centralWidget->setLayout(v);
setCentralWidget(centralWidget);
connect(forwardBut,SIGNAL(clicked()),this,SLOT(monthForward()));
connect(backwardBut,SIGNAL(clicked()),this,SLOT(monthBackward()));
}
void MainWindow::monthForward()
{
MonthLbl->setText(selectedDate.longMonthName(++x));
if(x>12)
x=1;
}
void MainWindow::monthBackward()
{
MonthLbl->setText(selectedDate.longMonthName(--x));
if(x<2)
x=13;
}
To copy to clipboard, switch view to plain text mode
with regards
Bookmarks