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