Floating QCalendarWidget over QTableView cell in delegate

  • Hi,

    I have a QStyledItemDelegate which is supposed to display a QCalendarWidget in table cell. Currently it looks like this:
    It is working, but it is impossible to use it as it is too small. Is it possible to "float" the QCalendarWidget over several cells creating a usable size?
    This is the code I currently have:

    #include "adoptdatefixdelegate.h"
    adoptDateFixDelegate::adoptDateFixDelegate(QObject* parent) : QStyledItemDelegate(parent) {
    QWidget* adoptDateFixDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const {
      QWidget* ca = new QWidget( parent );
      QCalendarWidget* adoptDateWidget = new QCalendarWidget(ca);
      adoptDateWidget->setStyleSheet ("background-color:rgb(255,217,229);" );
    //  adoptDateWidget->setMaximumWidth (100);
    //  adoptDateWidget->setMinimumWidth (100);
    //  adoptDateWidget->setMaximumHeight (30);
    //  adoptDateWidget->setMinimumHeight (30);
      QDate date;
      date = adoptDateWidget->selectedDate ();
    //  adoptDateWidget->setDateTextFormat (date, "MM/DD/YYYY");
      QFont calFont("Arial", 14);
      adoptDateWidget->setFont (calFont);
      adoptDateWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
      QVBoxLayout* adoptLayout = new QVBoxLayout;
      adoptLayout->addWidget (adoptDateWidget, 0, Qt::AlignCenter);
      adoptLayout->setMargin (2);
      ca->setLayout (adoptLayout);
      return ca;

    Thank you for your help.

  • Lifetime Qt Champion

    What about using a dialog ?
    When user click in cell - you pop a dialog and let him choose
    a date. On ok, you close the dialog.
    Creating a floating QCalendarWidget would require some
    clever coding to close at the right times. like when scrolling etc.

  • @mrjj
    Thank you. It works.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.