Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Activating calender popup on focus in event

[Solved]Activating calender popup on focus in event

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.1k Views
  • 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.
  • D Offline
    D Offline
    deepakberiwal
    wrote on last edited by
    #1

    I have a requirement in which I want to activate the calender popup using the keyboard. But the problem is that, in the focus in event the popup doesn't work.

    Please let me know if I need to change the approach or add something more that I am missing.

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

      see my DocNote on the "QTimeEdit":http://qt-project.org/doc/qt-4.8/qdatetimeedit.html. You could do something like that in your focus event handler method:

      @
      void MyDateEdit::focusInEvent ( QFocusEvent * event )
      {
      QStyleOptionComboBox opt;
      this->initStyleOption(&opt);
      QRect rect = this->style()->subControlRect(QStyle::CC_ComboBox,&opt,QStyle::SC_ComboBoxArrow);

       QMouseEvent event(QEvent::MouseButtonPress, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
       QApplication::sendEvent(this, &event);
      
       QMouseEvent event(QEvent::MouseButtonRelease, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
       QApplication::sendEvent(this, &event);
      
       QDateEdit::focusInEvent(event);
      

      }
      @

      this should open the calendar popup on focus in.

      --- 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

      P 1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Since dateEdit inherits QAbstractSipnBox: you need to make few modification to the above code,

         @QStyleOptionSpinBox opt;
        

        initStyleOption(&opt);

        QRect rect = this->style()->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC_SpinBoxDown);@

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

          no, because when the calendar popup is enabled the time edit looks more like a combobox than a spinbox right?
          And thats even the code QDateTimeEdit uses itself to paint the calendar button internally btw.

          --- 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
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            But the code didnt work with QStyleOptionComboBox.

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

              yes you are right.. .sorry.
              It over-hasted when i looked it up from some old code of mine.

              --- 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
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                It happens no worries :)

                1 Reply Last reply
                0
                • raven-worxR raven-worx

                  see my DocNote on the "QTimeEdit":http://qt-project.org/doc/qt-4.8/qdatetimeedit.html. You could do something like that in your focus event handler method:

                  @
                  void MyDateEdit::focusInEvent ( QFocusEvent * event )
                  {
                  QStyleOptionComboBox opt;
                  this->initStyleOption(&opt);
                  QRect rect = this->style()->subControlRect(QStyle::CC_ComboBox,&opt,QStyle::SC_ComboBoxArrow);

                   QMouseEvent event(QEvent::MouseButtonPress, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                   QApplication::sendEvent(this, &event);
                  
                   QMouseEvent event(QEvent::MouseButtonRelease, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                   QApplication::sendEvent(this, &event);
                  
                   QDateEdit::focusInEvent(event);
                  

                  }
                  @

                  this should open the calendar popup on focus in.

                  P Offline
                  P Offline
                  phnhung98
                  wrote on last edited by
                  #8

                  @raven-worx I need to do something similar but I do not want to subclass QDateEdit and use focusInEvent(), I use eventFilter in my MainWindow class. Is it possible to use your code?

                  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 Extensions
                  • Unsolved