Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Want the currentdate in QCalendarWidget to be underlined

  1. #1
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Want the currentdate in QCalendarWidget to be underlined

    hello friends,I want the current date in QCalendar widget to be underlined always ,so how can we do it,because in default calendar widget,it highlights it for the first time but when we change the selection ,the current date disappears,so i want it to be identified by some marker even if we selected a different date in QCalendar widget.


    regards
    ranjit

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Show the code you tried so far.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Try with QCalendarWidget::setDateTextFormat.

    For example

    Qt Code:
    1. cw->setDateTextFormat(QDate::currentDate, textFormat);
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    thanks mcosta,i got it,one morething i need to ask you,can i add a background image to cells of calendarwidget,please help me,i came to know that we have tp re-implement the paintcell method,but how to re-implement it i am not getting

  5. #5
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    You have to inherit a class from QCalendarWidget and reimplement the method QCalendarWidget::paintCell.
    For example

    Qt Code:
    1. void MyCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
    2. {
    3. painter->save(); // save standard settings
    4.  
    5. painter->setBrush (this->myBrush); // myBrush is a class member that store your background image
    6.  
    7. QCalendarWidget::paintCell (painter, rect, date);
    8.  
    9. painter->restore(); // restore previous settings
    10. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  6. #6
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    thanks i will work on it..


    Added after 17 minutes:


    Hey mcosta,I have taken a Qcalendarwidget on a form,and in the constructor i have written this code,so whether its correct,please help me out

    Qt Code:
    1. QPainter *p=new QPainter();
    2. p->begin()
    3. QRect r1(100,200,11,16);
    4. QRect r2(100,200,11,16);
    5. QImage image("C:/speedback.png");
    6. p->drawImage(r1,image,r2);
    7. ui->calendarWidget->paintCell(p ,r1,QDate::currentDate());
    To copy to clipboard, switch view to plain text mode 

    regards
    ranjit
    Last edited by high_flyer; 19th April 2011 at 13:18. Reason: code tags

  7. #7
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    hello friends please explain me out

  8. #8
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Are you sure that your code has not compilation errors?

    QCalendarWidget::paintCell is protected, so you can't call it.
    A camel can go 14 days without drink,
    I can't!!!

  9. #9
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    yes mcosta,i got that error,so i made it public and it got executed ,but i didnt see that image , how to solve this issue? and whether i coded it correctly or something is missing,


    thanks
    ranjit

  10. #10
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Quote Originally Posted by ranjit.kadam View Post
    yes mcosta,i got that error,so i made it public and it got executed
    What means???
    You cannot modify the QCalendarWidget code.
    QCalendarWidget::paintCell is automatically called from QCalendarWidget::paintEvent, so you need to reimplement it.

    Try with the code I suggested before
    A camel can go 14 days without drink,
    I can't!!!

  11. #11
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    ok i will try and get back to you

  12. #12
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Sorry,

    probably in my code calling QCalendarWidget:aintCell doesn't work.

    You have to draw the cell by hands

    For Example

    Qt Code:
    1. void MyCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
    2. {
    3. painter->save ();
    4.  
    5. painter->fillRect (rect, Qt::cyan);
    6. painter->drawText (rect, Qt::AlignCenter | Qt::AlignHCenter,
    7. QString::number (date.day ()));
    8.  
    9. // More painting
    10.  
    11. painter->restore ();
    12. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  13. #13
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Qt Code:
    1. void Dialog::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
    2. {
    3. painter->save(); // save standard settings
    4.  
    5. painter->setBrush (this->myBrush); // myBrush is a class member that store your background image
    6.  
    7. QRectF target(10.0, 20.0, 80.0, 60.0);
    8. QRectF source(10.0, 20.0, 70.0, 40.0);
    9. QImage image("C:/speedback.png");
    10. QRectF rect(100.0, 200.0, 80.0, 60.0);
    11.  
    12. painter->drawImage(target, image, source);
    13.  
    14. ui->calendarWidget->paintCell (painter, rect, date);
    15.  
    16. painter->restore(); // restore previous settings
    17. }
    To copy to clipboard, switch view to plain text mode 


    i tried your code,but i am getting the following errors.

    QCalendarwidget :aintcell is protected..
    QRect rect shadows a parameter.
    Last edited by high_flyer; 20th April 2011 at 10:47. Reason: code tags

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Please use code tags when you post code!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  15. #15
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    Quote Originally Posted by mcosta
    You have to inherit a class from QCalendarWidget and reimplement the method QCalendarWidget:: paintCell.
    Do you understand what I mean for "inherit a class from QCalendarWidget" ??
    If you don't, you have to study about C++ inheritance.
    A camel can go 14 days without drink,
    I can't!!!

  16. #16
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    yes mcosta,but i am getting confused because i have not coded for QCalendarwidget,i have directly taken it through designer

  17. #17
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    ok,

    create your class inherited from QCalendarWidget and then use Widget Promoting in Designer
    A camel can go 14 days without drink,
    I can't!!!

  18. #18
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    //widget.h
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include<QtGui>
    6. namespace Ui {
    7. class Widget;
    8. }
    9.  
    10. class Widget : public QWidget,QCalendarWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit Widget(QWidget *parent = 0);
    16. ~Widget();
    17.  
    18. private:
    19. Ui::Widget *ui;
    20.  
    21. private slots:
    22. void paintEvent(QPaintEvent *);
    23. };
    24.  
    25. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 

    widget.cpp

    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include<QPainter>
    4. #include<QFont>
    5. Widget::Widget(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::Widget)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. Widget::~Widget()
    13. {
    14. delete ui;
    15. }
    16. void Widget::paintEvent(QPaintEvent *)
    17. {
    18. QPainter painter(this);
    19. painter.setPen(Qt::red);
    20. painter.setBrush(Qt::green);
    21. painter.setFont(QFont("Ariel",30));
    22. painter.drawText(rect(),Qt::AlignCenter,"Qt");
    23. QRectF rect(100.0, 200.0, 80.0, 60.0);
    24. int startAngle = 50 * 16;
    25. int spanAngle = 120 * 16;
    26.  
    27.  
    28. painter.drawChord(rect, startAngle, spanAngle);
    29. painter.fillRect(10,200,80,60,Qt::green);
    30. painter.drawEllipse(rect);
    31.  
    32. QRectF target(10.0, 20.0, 80.0, 60.0);
    33. QRectF source(10.0, 20.0, 70.0, 40.0);
    34. QImage image("C:/speedback.png");
    35.  
    36.  
    37. painter.drawImage(target, image, source);
    38.  
    39.  
    40. painter.end();
    41.  
    42. }
    43.  
    44. void Widget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
    45. {
    46. painter->save(); // save standard settings
    47.  
    48. //painter->setBrush (this->myBrush); // myBrush is a class member that store your background image
    49.  
    50. painter->setBrush(Qt::VerPattern);
    51. QRect rect(100, 200, 80, 60);
    52. painter->drawEllipse(rect);
    53.  
    54. ui->calendarWidget->paintCell (painter, rect, date);
    55.  
    56. painter->restore(); // restore previous settings
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 

    can i do in this way

    or this way http://doc.trolltech.com/4.7.1/uitoo...heritance.html
    Last edited by ranjit.kadam; 20th April 2011 at 12:37.

  19. #19
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    can i do in this way
    First indication will be if the code compiles.
    So try to compile it first.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  20. #20
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Want the currentdate in QCalendarWidget to be underlined

    no hiflyer,i am getting error,
    error:
    request for member show ambiguous
    candidates are void QWidget::show();

Similar Threads

  1. Replies: 1
    Last Post: 6th November 2009, 10:03
  2. How to make some part of text underlined in QLineEdit?
    By blonde in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 09:43
  3. How to make a QString text underlined?
    By blonde in forum Newbie
    Replies: 5
    Last Post: 29th October 2009, 08:19
  4. Replies: 0
    Last Post: 16th July 2009, 15:58
  5. about QCalendarWidget
    By nifei in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2009, 09:17

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.