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. QCalendarWidget tooltip
Qt 6.11 is out! See what's new in the release blog

QCalendarWidget tooltip

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 875 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!!

    Does anyone know how to assign a tooltip to each of the cells in a qcalendarwidget?

    Thank you very much!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the looks of it, you will have to install an event filter to catch the QEvent::ToolTip event and react on that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ivanicyI 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        From the looks of it, you will have to install an event filter to catch the QEvent::ToolTip event and react on that.

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        @SGaist Can you help me with that? I read that I need to reimplement the QCalendarWidget class. I have this class:

        #include "calendarmanager.h"
        
        CalendarManager::CalendarManager(QWidget *parent)
            : QCalendarWidget (parent)
        {
        //    m_outlinePen.setColor(QColor(213,116,23));
            m_outlinePen.setColor(Qt::transparent);
            m_transparentBrush.setColor(QColor(213,116,23,50));
        
            getDates();
        }
        
        CalendarManager::~CalendarManager()
        {
        
        }
        
        void CalendarManager::setColor(const QColor &color) {
            m_outlinePen.setColor(color);
        }
        
        QColor CalendarManager::getColor() const {
            return ( m_outlinePen.color() );
        }
        
        void CalendarManager::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const {
            QCalendarWidget::paintCell(painter, rect, date);
        
            if (m_dates.contains(date)) {
                painter->setPen(m_outlinePen);
                painter->setBrush(QBrush(QColor(213,116,23,50)));
                painter->drawRect(rect.adjusted(0, 0, -1, -1));
            }
        }
        
        void CalendarManager::getDates() {
        //    QFile file("C:\\Users\\Ivan\\Desktop\\prueba.txt");
        //    if (!file.open(QIODevice::ReadOnly)) {
        //        // Error code
        //    }
        
        //    QList<QByteArray> wordList;
        //    QDate date;
        //    QString name;
        //    calendarEvent e;
        
        //    while (!file.atEnd()) {
        //        QByteArray line = file.readLine();
        //        wordList = line.split(',');
        
        //        date = QDate::fromString(wordList.first(), "dd/MM/yyyy");
        //        name = wordList.last();
        
        //        e.date = date;
        //        e.name = name;
        
        //        m_events.append(e);
        //        m_dates.append(date);
        //    }
        //    file.close();
        }
        
        void CalendarManager::setDateState(QDate dtDate, bool bState) {
            /* Esta es la funcionalidad mínima necesaria para pintar un día en el calendario */
            calendarEvent e;
            e.date = dtDate;
        
            if (bState) {
                m_events.append(e);
                m_dates.append(dtDate);
            } else {
                for (int iDate = 0; iDate < m_events.size(); iDate++) {
                    if (m_events.at(iDate).date == e.date)
                        m_events.removeAt(iDate);
                    if (m_dates.at(iDate) == e.date)
                        m_dates.removeAt(iDate);
                }
            }
        }
        
        

        How I have to proceed with the event filter? I think I read that I need it inside the paintCell function but I don't know how to do it.

        Thank you very much!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You have an example of event filter here.

          What kind of tool tip do you want to show ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ivanicyI 1 Reply Last reply
          0
          • SGaistS SGaist

            You have an example of event filter here.

            What kind of tool tip do you want to show ?

            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @SGaist I only want to show a simple text associated to the selected day

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In your event filter get the Qt's event and then us a QToolTip to check the dialog you want to build.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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