How to Develop a Calendar Widget.
-
That's because you are trying something that is not allowed and makes no sense when you think about it. The calendar widget will be shown within a dialog. The calendar widget is not a dialog. So use composition not inheritcance for the dialog aspect.
@
class MyCalendarWidget : public QCalendarWidget
{
...
protected:
virtual void paintCell(QPainter* painter, const QRectF& rect, const QDate& date)
{
// Do custom painting here!!! See base class for default implementation and ideas
}
};...
...
...class MyDialog : public QDialog
{
...
};
@ -
Hello ZapB
thanks for ur reply..
Actually when i use the code like that
class PainterApp : public QDialog,public Ui::Dialog//name of your form..
than error is
// invalid use of incomplete type struct Ui::PainterApp//my form name come..
and one more thing i hv calender widget present in QtDesigner..which means i havent create my own custom calender..
regards
Anshuman -
[quote author="BorahAnshuman" date="1303303682"]Hello ZapB
and one more thing i hv calender widget present in QtDesigner..which means i havent create my own custom calender..
[/quote]So do what I suggested and create one. You cannot override the paintCell() function if you do not have a sub-class of QCalendarWidget can you? This is basic C++.
-
ok ZapB I am sending my code u please check it..now no error signifies but nothing display in the cell..
@namespace Ui {
class PainterApp;
}
class MyCalendarWidget : public QCalendarWidget
{
private:
Ui::PainterApp ui;
protected:
virtual void paintCell(QPainter painter, const QRectF& rect, const QDate& date);};
class PainterApp : public QDialog
{
Q_OBJECTpublic:
explicit PainterApp(QWidget *parent = 0);
~PainterApp();private:
Ui::PainterApp *ui;
private slots:};@
@#include "painterapp.h"
#include "ui_painterapp.h"PainterApp::PainterApp(QWidget *parent) :
QDialog(parent),
ui(new Ui::PainterApp)
{
ui->setupUi(this);}
void MyCalendarWidget::paintCell(QPainter* painter, const QRectF& rect, const QDate& date)
{rect(30.0, 40.0, 80.0, 60.0); QImage image("C:/QTWork/back-icon.png"); painter->drawImage(rect, image, rect); ui->calendarWidget->paintCell(painter,rect,date.currentDate());
}
@regards
Anshuman -
A few issues for you to consider/fix:
Whay are your trying to change the rect passed into the paintCell() call. This is setup to tell you where to draw by the base class. Do not change it.
Why are you trying to include the ui for something totally unrelated into your sub-class of QCalendarWidget?
It seems you have no conceptual idea of how Qt widgets, dialogs, ui files etc relate to each other. I respectfully suggest that you go work through some of the many examples and tutorials shipped with Qt.
-
hi Zapb
Actually i am new in Qt..more ever all of other people are new in Qt..so no one was there to guide me..ok i will..if u dont mind can u sent some material regarding Qt..actually i hv go through the documentation but it difficult to understand..
if possible u can send me some material regarding Qt i my email address
borah.anshu@gmail.comwith regards
Anshuman -
Qt Documentation and examples shipped with Qt are the best docs and materials for learning Qt I think.
-
You can reffer to this link as an example http://doc.qt.io/qt-5/qtwidgets-widgets-calendarwidget-example.html