Results 1 to 8 of 8

Thread: Calendar Pop Up

  1. #1
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    7

    Default Calendar Pop Up

    Hi ,

    I have a QdateEdit and Qbutton. Whenever I click on the button the calendar of the dateedit should be poped up.

    I have tried to make a calendarwidget as given in the attachment. Intially I have made setVisible(false) for the calendar widget. Then I connected the click event of the button to setVisible(true) for the calendar widget. It's working fine. But this component is to be placed on another container. It has limited space. I can't give space for the calendar widget in the container. So it's hidding the view of calendar widget.

    In stead of doing this if any way I can make the calendar of Dateedit visible the problem will be solved.

    Please give me some idea to resolve it.

    Thanks and Regards,
    Rakesh
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Calendar Pop Up

    You don't need a separate button. QDateTimeEdit (notice that QDateEdit is a QDateTimeEdit) has built-in support for a "calendar popup". Look into QDateTimeEdit docs for more details.
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    7

    Default Re: Calendar Pop Up

    Hi ,

    Thanks for your reply. I know that QDateTimeEdit has a property to setcalendarpopup.
    But my project requirement is we need a separate button so that we can have an icon for the button. Whenever I click on the icon the calendar should popped up.

    So please give me some idea how to do it.

    Regards,
    Rakesh

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Calendar Pop Up

    You mean something like this?
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QWidget window;
    8. QToolButton* toolButton = new QToolButton(&window);
    9. toolButton->setText("QToolButton");
    10. QPushButton* pushButton = new QPushButton("QPushButton", &window);
    11. QHBoxLayout* layout = new QHBoxLayout(&window);
    12. layout->addWidget(toolButton);
    13. layout->addWidget(pushButton);
    14. window.show();
    15.  
    16. QMenu* toolMenu = new QMenu(toolButton);
    17. QCalendarWidget* toolCalendar = new QCalendarWidget(toolMenu);
    18. QWidgetAction* toolAction = new QWidgetAction(toolMenu);
    19. toolAction->setDefaultWidget(toolCalendar);
    20. toolMenu->addAction(toolAction);
    21. toolButton->setMenu(toolMenu);
    22.  
    23. QMenu* pushMenu = new QMenu(pushButton);
    24. QCalendarWidget* pushCalendar = new QCalendarWidget(pushMenu);
    25. QWidgetAction* pushAction = new QWidgetAction(pushMenu);
    26. pushAction->setDefaultWidget(pushCalendar);
    27. pushMenu->addAction(pushAction);
    28. pushButton->setMenu(pushMenu);
    29.  
    30. QObject::connect(toolCalendar, SIGNAL(currentPageChanged(int, int)), pushCalendar, SLOT(setCurrentPage(int, int)));
    31. QObject::connect(pushCalendar, SIGNAL(currentPageChanged(int, int)), toolCalendar, SLOT(setCurrentPage(int, int)));
    32. QObject::connect(toolCalendar, SIGNAL(clicked(QDate)), pushCalendar, SLOT(setSelectedDate(QDate)));
    33. QObject::connect(pushCalendar, SIGNAL(clicked(QDate)), toolCalendar, SLOT(setSelectedDate(QDate)));
    34.  
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 
    QToolButton is a bit more flexible because it offers different popup modes. The default popup mode is delayed.
    J-P Nurmi

  5. #5
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    7

    Default Re: Calendar Pop Up

    Hi,

    Thanks a lot. It's really matches my requirement.

    Now I am using QPushButton as you explained in the code. One problem is I am not able to set the location for the calendar widget. I tried pushCalendar->setGeometry(). but it's not working.

    Is there any way I can set the position for Calendar widget?

    Regards,
    Rakesh

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Calendar Pop Up

    You can show the calendar as a top level popup yourself in response to a button click, instead of (ab)using the readily available button menu functionality.
    J-P Nurmi

  7. #7
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    7

    Default Re: Calendar Pop Up

    Hi ,

    Thanks a lot for your reply. I am not aware how to implement this. Could you please provide me a sample code for doing this?

    Regards,
    Rakesh

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Calendar Pop Up

    Quote Originally Posted by Rakesh_Kumar View Post
    I am not aware how to implement this. Could you please provide me a sample code for doing this?
    No, I won't code it for you just like that. This is not a coding service forum. Please try at least something on your own. Here are some hints: QAbstractButton::clicked(), QCalendarWidget and Qt::Popup.
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    Rakesh_Kumar (8th December 2008)

Similar Threads

  1. Opensource Calendar Widget
    By donmorr in forum Qt Tools
    Replies: 5
    Last Post: 15th February 2012, 18:54
  2. having some problems
    By Barvik in forum Newbie
    Replies: 0
    Last Post: 19th November 2008, 14:21
  3. Calendar widget with selectionMode != SingleSelection
    By Tamara in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2007, 10:13
  4. QDateEdit read-only with calendar not r.o.
    By lauranger in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2007, 17:14
  5. Extending QDate, QTime and QDateTime
    By jamadagni in forum Qt Programming
    Replies: 8
    Last Post: 24th March 2006, 15:51

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.