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. Decreasing the size of QCalendarWidget

Decreasing the size of QCalendarWidget

Scheduled Pinned Locked Moved General and Desktop
qcalendarwidget
2 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    air57
    wrote on last edited by
    #1

    I have used the QCalendarWidget without difficulty in the past but now have an application where I need a more compact presentation. Decreasing the font size and eliminating the headers still leaves too much space for each date item. A trial of using just a QTableView allows me to size the cells appropriately but the QCalendarWidget does not expose the underlying view class.

    I tried using the ::item portion of the stylesheet for both the calendar widget and QTableView but it has no effect.

    The only option I see is to create a QTableView class and populate the model using some code pulled from the QCalendarWidget class but this seems a bit of a chore.

    I'm looking for something similar to the compact web calendar controls. Any suggestions would be greatly appreciated.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      venturajpo
      wrote on last edited by
      #2

      To decrease the size of QCalendarWidget you have to find the QTableView inside QCalendarWidget and then set the headers size to zero (or any size you want). You can also set the font size to a small (but visible) value.

      In the following code cal is a pointer to QCalendarWidget

      QTableView* calendarView = 0;
          for(auto i : qAsConst(cal->children()))
          {
              calendarView = dynamic_cast<QTableView*>(i);
              if(calendarView)
              {
                  qDebug() << "View Found";
                  QHeaderView* hh = calendarView->horizontalHeader();
                  QHeaderView* vh = calendarView->verticalHeader();
                  QFont font = calendarView->font();
                  font.setPointSize(8);
                  calendarView->setFont(font);
      
                  hh->setMinimumSectionSize(0);
                  vh->setMinimumSectionSize(0);
              }
          }
      
      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