How to Develop a Calendar Widget.
-
Hello Andre,thanks for your code snippet,its setting the color of the cells specified,I have one question,actually I want to set the colors of the cells in Qcalendarwidget by clicking a button say "set",which is present in another dialog,So when i click on set and close the new dialog all the color changes should be reflected in my main-dialog which contains qcalendarwidget..
thanks &Regards
imrrk -
- Hi andre,I have my dialog.ui where I have dragged qcalendar widget and one push button and on click of this pushbutton,I have written the code for setting of colors in different cells,and its working 100% fine.
- Now I have one more " dialog1.ui" and in designer mode again I dragged two radio buttons."1-set" and "2-unset".Now I have two options with radiobuttons for setting and unsetting colors,so i will select radiobutton 1-set and press ok pusshbutton in dialog1.ui,* So when I press this button in dialog1.ui the colors should get set to cells in my previous dialog.ui which contains qcalendarwidget.So i am confused about how to do that.
-
What have you tried so far? Did you use the code snippets that you were shown earlier in this thread, on how to display a dialog based on a click? As you have been told before: we are not going to write your software for you, even if that would be way faster than trying to help you do it yourself.
-
Hello Andre..yes I have used the code snippets,and i know how to display the dialog based on a click,and i can link many forms ,and I am not asking you to write my software,as you are a qt expert,I m asking you,and as you are a qt expert my question may appear silly for you.I dont want you to write my software,but if you have understood my above question,then I request you to tell me the direction so that I can achieve my destination..
thanks&Regards
imrrk -
There is no need to grovel, just a need to understand what you are asking me (us) to do. You are asking me for general help, but you are not showing (only telling when asked) how far you got along yourself. That makes it very hard to give specific help without dropping big amounts of code here in the forum, hoping that that will contain a solution for whatever problem you seem to be having.
So, please, show us the relevant code that you have now for dealing with this issue: how you store the days to highlight now, how you respond to the mouse click, what your dialog looks like, and give a precise description of what it is you're struggling with. Please, do write that description in short, but full sentences. That is, with all the proper punctuation marks like points, comma's where needed (not like the above), and if appropriate, using bullet lists or other devices. Your texts are often very hard to read, and that makes it hard to understand your actual question. The time spend to formulate a good, understandable question is not time that you waste, but is in fact very useful also for yourself to order your thoughts on the topic.
-
Hello Andre,thank you for making understand me the rules of the forum.
So here is my code so far.
@#include "dialog.h"
#include "ui_dialog.h"
#include<QCalendarWidget>
#include<QDate>
#include "dialog1.h"
#include "ui_dialog1.h"
#include<QPainter>Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);}
Dialog::~Dialog()
{
delete ui;
}void Dialog::on set_clicked()
{colddate.setBackground(Qt::yellow);//colddate has been declared in .h file it is a object of QTextCharFormat
hotdate.setBackground(Qt::red);
wetdate.setBackground(Qt::green);
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);
}void Dialog::on unset_clicked()
{colddate.clearBackground();//function to clear the background
hotdate.clearBackground();
wetdate.clearBackground();
raindate.clearBackground();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);
}
@
Here I have used the designer for qcalendarwidget and two pushbuttons which i have named set and unset respectively,and wriiten the code for click as shown above.Now these 3 widgets are on one form,and they work perfectly.
But if the push buttons are on different form,and Qcalendar widget on another form,then when i click on these,how can set colors of qcalendarwidget which is in the another form.and also I tried to add backgroundimage to cell using
colddate.BackgroundImageUrl.... -
Declare your own two signals (setClicked() and unsetClicked()) in the second form, emit these signals once the respective button is clicked. In your first dialog create two slots (eg. setWeatherColors() and unsetWeatherColors()). These slots contain the code from on_set_clicked and on_unset_clicked. Connect the two signals from the second dialog to the slots in the first (do this in the very same place where you instantiate the second dialog).
If you do not know how to declare signals and slots: Start reading "here":http://doc.qt.nokia.com/4.7/signalsandslots.html#signals, the page contains a complete example for both.
-
You would use the code for showing a new dialog that I gave you earlier. That is: you create the new dialog, set the data on it that you need to do proper editing, exec() it, and read back the new value through a public method on your dialog that you have created for that purpose.
What I don't understand in the sample that you are currently showing, is why you are re-setting the actual formats, instead of changing or removing the set format for the date that you are editing. I would keep the hotDate and coldDate formats themselves constant, and just change which one you set on which date. That would make more sense, I think.
-
Hello Volker,here is my code according to your suggestion.
dialog1.h//declaring signals@#ifndef DIALOG1_H
#define DIALOG1_H#include <QDialog>
#include<QDate>
#include<QTextFormat>
namespace Ui {
class Dialog1;
}class Dialog1 : public QDialog
{
Q_OBJECTpublic:
explicit Dialog1(QWidget *parent = 0);
~Dialog1();private:
Ui::Dialog1 *ui;private slots:
// void on_radioButton_clicked();
signals:
void setclicked();
void unsetclicked();private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
};#endif // DIALOG1_H
@dialog1.cpp//emitting the signals
@
#include "dialog1.h"
#include "ui_dialog1.h"
#include<QCalendarWidget>
Dialog1::Dialog1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog1)
{
ui->setupUi(this);
connect(ui->pushButton,SIGNAL(setclicked()),this,SLOT(setcolors()));
connect(ui->pushButton_2,SIGNAL(unsetclicked()),this,SLOT(unsetcolors()));
}Dialog1::~Dialog1()
{
delete ui;
}void Dialog1::on_pushButton_clicked()
{
emit setclicked();
}void Dialog1::on_pushButton_2_clicked()
{
emit unsetclicked();
}
@whether I am correct.?
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.
-
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?