QCalendar Widget focus problem
-
Hi,
i'm using Qt 5.15.0 on Mac Os X
in my application clicking on a tableview's cell must appear a Calendar (QCalendarWidget)my problem is that the calendar popup was showed behind the dialog (seem that has no focus).
if i move the dialog with mouse and re-click on tableview the calendar appear and work fine (to select a date and insert it into tableview cell)
how can i resolve this visualization problem?
Thanks in advance.
Calendario popup; int result1 = popup.exec(); if(result1 == QDialog::Accepted){ QDate date = popup.selectedDate(); if (date < Oggi) { msg.setText("ATTENZIONE: Data precedente ad Oggi!"); msg.exec(); return; } data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); // OrdModel is a tableview
this is Calendario header file
#ifndef DATEPOPUP_H_ #define DATEPOPUP_H_ #include <QDialog> #include <QDate> class QCalendarWidget; class QDialogButtonBox; class QVBoxLayout; class Calendario : public QDialog{ Q_OBJECT public: Calendario(QWidget *parent=nullptr); QDate selectedDate() const; private: QWidget *widget; QCalendarWidget *calendarWidget; QDialogButtonBox* buttonBox; QVBoxLayout *verticalLayout; }; #endif /* DATEPOPUP_H_ */
and this is calendario .cpp file
#include <QtGui> #include "calendario.h" #include <QVBoxLayout> #include <QCalendarWidget> #include <QDialogButtonBox> Calendario::Calendario(QWidget *parent) :QDialog(parent, Qt::Popup) { setSizeGripEnabled(false); resize(520, 460); widget = new QWidget(this); widget->setObjectName(QString::fromUtf8("widget")); widget->setGeometry(QRect(0, 10, 516, 430)); verticalLayout = new QVBoxLayout(widget); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); calendarWidget = new QCalendarWidget(widget); calendarWidget->setObjectName(QString::fromUtf8("calendarWidget")); verticalLayout->addWidget(calendarWidget); buttonBox = new QDialogButtonBox(widget); buttonBox->setObjectName(QString::fromUtf8("buttonBox")); buttonBox->setOrientation(Qt::Horizontal); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); verticalLayout->addWidget(buttonBox); QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); } QDate Calendario::selectedDate() const{ return calendarWidget->selectedDate(); }
-
i've updated the first post and add calendario.cpp code
i gave dialog as a parent
Calendario popup(this);
but in this case the popup calendar is moved with the dialog (worse than before..) when i move it with the mouse
always behind the dialog
some time ago everything works great
i didn't change anything but now don't works like before
-
Hi,
Why do you have that
widget
member variable ? It just sits on top of your dialog and does not add anything useful to the handling, even worse, if you resize your dialog,widget
will not follow.I would remove it.
-
That I don't know.
Can you show exactly how you are using it ? The code you posted does not show that in the context of your application.
-
ok, i have a dialog with a tebleview
and when i click on a specific cell ("Data C1" for example) will appear a Calendar where i can select date
void inserimentoordini::on_tableView_pressed(const QModelIndex &index) { QMessageBox msg; //msg.setText("Riga: " + QString::number(index.row()) + " Colonna: " + QString::number(index.column())); //msg.exec(); //Select Case QDate Oggi = QDate::currentDate(); QString data; int x = index.column(); switch (x) { case (1): //Data Conf 1 { //Calendario popup(this); Calendario popup; popup.setModal(true); int result1 = popup.exec(); if(result1 == QDialog::Accepted){ QDate date = popup.selectedDate(); if (date < Oggi) { msg.setText("ATTENZIONE: Data precedente ad Oggi!"); msg.exec(); return; } //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; case (3): //Data Conf 2 { Calendario popup; int result2 = popup.exec(); if(result2 == QDialog::Accepted){ QDate date = popup.selectedDate(); //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; case (5): //Data Conf 3 { Calendario popup; int result5 = popup.exec(); if(result5 == QDialog::Accepted){ QDate date = popup.selectedDate(); //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; case (7): //Data Prev 1 { Calendario popup; int result7 = popup.exec(); if(result7 == QDialog::Accepted){ QDate date = popup.selectedDate(); //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; case (9): //Data Prev 2 { Calendario popup; int result9 = popup.exec(); if(result9 == QDialog::Accepted){ QDate date = popup.selectedDate(); //QMessageBox msg; //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; case (11): //Data Prev 3 { Calendario popup; int result11 = popup.exec(); if(result11 == QDialog::Accepted){ QDate date = popup.selectedDate(); //QMessageBox msg; //msg.setText(date.toString("dd-MM-yyyy")); //msg.exec(); data = date.toString("dd-MM-yyyy"); data.replace("-","/"); OrdModel->itemFromIndex(index)->setText(data); } return; } break; default: //istruzioni break; } }
-
Why not use a QStyledItemDelegate to handle that column ?
-
i've created a new project with a mainwindow and a pushbutton
on pushbutton click load the dialog with the calendar..
everything works: popup calendar was opened and it's on top!
the used code is the same..
i can't understand where the problem is..
someone can help me?
(
i've found the problem:
Mainwindow: with a pushbutton i can open a first dialog and with another pushbutton a second dialog (popup Calendar) -> everything ok
from the first dialog using a pushbutton i will open the second dialog (popup Calendar)
in this case the second dialog (popup Calendar) was opened but it wasn't on the top
it was behind the first dialog as you can see in the following image