How to Develop a Calendar Widget.
-
i didnt get you gerolf,can u please ellaborate..
thanks
imrrk -
You are now emitting signals from Dialog1 (you might want to think of a more descriptive name to improve code readability), but you are not handing these signals in slots. To fix that, you are going to need to define two slots in Dialog, and connect the signals to these slots.
-
hello andre,those slots i have defined in my previous dialog.cpp..ie setcolors() and unsetcolors(); and the above code is of the another dialog from where i am calling these slots.
-
So... if you have the slots (again: you did not show us, you just told us now after asking), and you have the signals (and, I hope, you have connected them), what is then the problem?
-
hello andre,these were the same slots which i had show earlier in this post..i was connecting those slots with signals in my second dialog,I hope you r getting me..
-
OK. Fine, you are re-using the slots you already had. Great, and sensible I suppose. And does that all work properly now?
-
Now Andre...its not working
-
Is the problem that you don't see the dialog pop up, or that the dates are not cleared when you click one of the buttons on the dialog?
Did you:
- actually connect the signals with the slots?
- check your output while running to see if the connection worked?
- put debug statements or breakpoints at the relevant places to track what breaks down exactly?
-
actually dates colors are not cleared,when i click on the buttons..
-
[quote author="Andre" date="1302698169"]Did you:
- actually connect the signals with the slots?
- check your output while running to see if the connection worked?
- put debug statements or breakpoints at the relevant places to track what breaks down exactly?
[/quote]
-
i will check it out and get back to u..thanks for your help
-
hwy volker i created two signals and i emitted them on click of push buttons,now in which dialog i should connect signals and which will be the sender and reciever ,I m not getting..
regards
imrrk -
The sender of the signal is typically the object, that sends them, the receivedr is the object that implements the slots.
so If you are inside the code of dlg1, which implements the slots and invoke there a dialog dlgh2 which emiuts the signals you do:
@
dlg1::foo()
{
dlg2 dlg;
connect(&dlg, SIGNAL(fooSignal()), this, SLOT(fooSlot()));
dlg.exec();
}
@ -
hey gerolf in dialog1.cpp ,i have emmitted two signals on click of push buttons and connected them as shown below..I dont know whether i am correct in this,now I have my maindialog1.cpp where i wriiten the slots for setting colors,now I am not getting how shall i make connections with the signals i emmitted in dialog1.cpp and the slots in my maindialog.cpp,which contains the slots..
@#include "dialog1.h"
#include "ui_dialog1.h"
#include<QCalendarWidget>
Dialog1::Dialog1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog1)
{
ui->setupUi(this);
connect(ui->set,SIGNAL(clicked()),this,SIGNAL(setclicked()));
connect(ui->unset,SIGNAL(clicked()),this,SIGNAL(unsetclicked()));
}Dialog1::~Dialog1()
{
delete ui;
}void Dialog1::on_set_clicked()
{
emit setclicked();
}void Dialog1::on_unset_clicked()
{
emit unsetclicked();
}
@
this my dialog.cpp//
@#include "dialog.h"
#include "ui_dialog.h"
#include<QCalendarWidget>
#include<QDate>
#include "dialog1.h"
#include "ui_dialog1.h"
#include<QPainter>
#include <QtGui/QApplication>Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
//Dialog1 a(this);
connect(&Dialog1,SIGNAL(setclicked(),this,SLOT(setcolors())));
connect(&Dialog1,SIGNAL(unsetclicked(),this,SLOT(unsetcolors())));// QCalendarWidget *cal=new QCalendarWidget();
// cal->setDateEditEnabled(1);
// cal->setFirstDayOfWeek(Qt::Wednesday);// cal->show();
//ui->calendarWidget->setFirstDayOfWeek(Qt::Thursday);//QTextCharFormat colddate;
//colddate.setBackground(Qt::yellow);//QTextCharFormat hotdate;
//hotdate.setBackground(Qt::red);//QTextCharFormat wetdate;
//wetdate.setBackground(Qt::green);//QTextCharFormat raindate;
//raindate.setBackground(Qt::blue);//ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),colddate);
//ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),hotdate);
//ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),wetdate);
//ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),raindate);
//ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),colddate);
//ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),hotdate);
}Dialog::~Dialog()
{
delete ui;
}void Dialog::on_calendarWidget_clicked(QDate date)
{
// ui->label->setText(date.toString());
//ui->textBrowser->setText(date.toString());
Dialog1 a(this);
a.show();
a.exec();// ui->pushButton->setText(QString::number(date.day()));
}
void Dialog::setcolors()
{safedate.setBackground(Qt::green); //safedate.BackgroundImageUrl
unsafedate.setBackground(Qt::yellow);
fertiledate.setBackground(Qt::red); startdate.setBackground(Qt::blue); ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),startdate); ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),safedate); ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),unsafedate); ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),fertiledate); ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),unsafedate); ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),safedate);
}
void Dialog::unsetcolors()
{
startdate.clearBackground();
safedate.clearBackground();
unsafedate.clearBackground();
fertiledate.clearBackground();
ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),startdate);
ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),safedate);
ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),unsafedate);
ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),fertiledate);
ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),unsafedate);
ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),safedate);
}@regards
imrrk -
In dialog.cpp, you need to make the connections not on lines 14 and 15, but where you actually create the dialog, after line 57. There you have a reference to both the dialogs, so there you make the connection.
-
thanks andre ,I got it and its working fine,thanks a lot
-
hey andre as we have set the background colors for the cells can we set the backgroundimage for the cells...by using,
QTextcharformat date;
date.setbackgroundimageurl -
if this function exists, try it out.
have a look at the docs. -
[quote author="imrrk" date="1302766931"]hey andre as we have set the background colors for the cells can we set the backgroundimage for the cells...by using,
QTextcharformat date;
date.setbackgroundimageurl[/quote]
Could you make your variable naming any more confusing? I mean: you're working with calendars and dates, and you call a variable that represents a text format date?Anyway, QTextCharFormat (or its base class QTextFormat) does not have a method setBackgroundImageUrl. At least, not that I could find. But you can use a QBrush instead of a color, so that opens up some more options as brushes can be quite fancy... Check the documentation of QBrush.
-
ok andre and gerolf,thanks for ur information,I will check out the doc and come up with some possibilities..
regards
imrrk
69/119