Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Calender Popup issue.
Qt 6.12 LTS is out! See what's new in the release blog

[Solved]Calender Popup issue.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    My requirement is to show --/--/---- in the QDateEdit as default, now after this when the user clicks on the down arrow the calender should popup with the current date, and the user should be able to select any date.

    Now to set --/--/---- I am using

    @dateEdit->setSpecialValueText("--/--/--");@

    this will show only when the set date is invalid, or doesnot lie in the range, so for that I am setting the date as 1,1,1 using

    @dateEdit->setDate(QDate(1,1,1));@

    After this when the user clicks on the down arrow the popup comes but it comes up with the year as 1752.

    Now I need calender popup to show the current date instead of this. I have checked lot but could not find any thing, and there is no signal that is being emitted when the QTimeEdit is clicked.

    Please let me know how can I proceed with this.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you can do the following to check if the user clicks on the popup button:
      @
      void MyTimeEdit::mousePressEvent(QMouseEvent* event)
      {
      QStyleOptionComboBox opt;
      this->initStyleOption(&opt);
      QRect rect = this->style()->subControlRect(QStyle::CC_ComboBox,&opt,QStyle::SC_ComboBoxArrow);
      if(rect.contains(event->pos()))
      {
      .... //do your stuff here
      }

      return QTimeEdit::mousePressEvent(event);
      

      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks for the reply, from you post I actually got the hint how to proceed.

        The approach I used is a bit different but it works well for me. I would like to share what I actually did.

        @bool QDateEdit::eventFilter(QObject *target, QEvent *event)
        {
        if (event->type()== QEvent::MouseButtonPress)
        {
        QMouseEvent *mevent = static_cast<QMouseEvent *>(event);
        if(mevent != NULL)
        {
        if(mevent->buttons() == Qt::LeftButton)
        {
        if (date() == minimumDate())
        setDate(QDate::currentDate());
        return QWidget::eventFilter(target,event);
        }
        }
        }
        }@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved