Results 1 to 8 of 8

Thread: Problem Subclassing Calendar

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem Subclassing Calendar

    I need to create a custom calendar, where i need to change the look of each cell that contains a date. I tried this:
    Qt Code:
    1. class CustomCalendarWidget : public QCalendarWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. CustomCalendarWidget( QWidget* parent = 0 ) : QCalendarWidget( parent ) {}
    6. ~CustomCalendarWidget() {}
    7.  
    8. protected:
    9. virtual void paintCell( QPainter* painter, const QRect& rect, const QDate& date ) const
    10. {
    11. painter->setPen( Qt::black );
    12. painter->drawText( rect, Qt::AlignCenter, tr("Qt by Nokia") ); //for example
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

    But i get errors:
    Qt Code:
    1. ..\Calendar_forum_v2\/customcalendarwidget.h: In member function 'virtual void CustomCalendarWidget::paintCell(QPainter*, const QRect&, const QDate&) const':
    2.  
    3. ..\Calendar_forum_v2\/customcalendarwidget.h:17: error: invalid use of incomplete type 'struct QPainter'
    4.  
    5. ..\..\..\NokiaQtSDK\Simulator\Qt\mingw\include/QtGui/qwindowdefs.h:68: error: forward declaration of 'struct QPainter'
    6.  
    7. ..\Calendar_forum_v2\/customcalendarwidget.h:18: error: invalid use of incomplete type 'struct QPainter'
    8.  
    9. ..\..\..\NokiaQtSDK\Simulator\Qt\mingw\include/QtGui/qwindowdefs.h:68: error: forward declaration of 'struct QPainter'
    To copy to clipboard, switch view to plain text mode 

    Could someone please explain to me - what am I doing wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem Subclassing Calendar

    You forgot to #include <QPainter>.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Archa4 (8th March 2011)

  4. #3
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem Subclassing Calendar

    Thanks Very much! (such an idiotic mystake by me)

    Hm now i have a different kind of problem: In original all the dates from previous and next month were not black colour but black. Now all the dates are black. How should i alter the void PaintCell to make the dates look like original? Can I look anywhere how the void PaintCell was working in original? That way i could alter mine realisation to make the dates from previous and next month gray...

    Thanks!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem Subclassing Calendar

    You could look into the source code for the method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem Subclassing Calendar

    Em.. I don't want to sound retarded, but where can i look in source code?

  7. #6
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem Subclassing Calendar

    Try this location:
    <your_qt_dir>/src/gui/widgets/qcalendarwidget.cpp

  8. #7
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem Subclassing Calendar

    Hm... I can only find QCalendarWidget.h files, but there are no QCalendarWidget.cpp anywhere...

    Well, with trials and errors i wrote this thing, that seems to be working:
    Qt Code:
    1. if (this->monthShown()!=date.month())
    2. painter->setPen(Qt::gray);
    3. else
    4. if (date.dayOfWeek()==6 || date.dayOfWeek()==7)
    5. painter->setPen(Qt::red);
    6. else
    7. painter->setPen(Qt::black);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Archa4; 9th March 2011 at 07:54.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem Subclassing Calendar

    Quote Originally Posted by Archa4 View Post
    Em.. I don't want to sound retarded, but where can i look in source code?
    Download Qt's sources and look there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Subclassing QSortFilterProxyModel problem
    By e79ene in forum Newbie
    Replies: 2
    Last Post: 21st February 2011, 13:23
  2. Subclassing QMainWindow problem
    By lerwys in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2009, 08:40
  3. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  4. Problem in SubClassing QTableItem.
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2006, 10:21
  5. subclassing/inheritance QObject problem
    By cbeall1 in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 17:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.