[SOLVED] QCalendarWidget.setDateEditEnabled(bool) does nothing.
-
Hi,
do you try this?
I've created the project with QtCreator, and with these instructions an user can't modify the calendar.@#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->calendarWidget->setEnabled(false);}
MainWindow::~MainWindow()
{
delete ui;
}@ -
I looked into this but there is no such function on the calendar widget, when the intellisense thing pops up. Looking at the docs also seems to confirm this. I am using 4.8.1
Also it seems the function I'm trying to use, doesn't do what the name sounds like it should, I'm new to QT so I'm not sure what it's talking about, from the docs....
dateEditEnabled : bool
This property holds whether the date edit popup is enabled.
If this property is enabled, pressing a non-modifier key will cause a date edit to popup if the calendar widget has focus, allowing the user to specify a date in the form specified by the current locale.
By default, this property is enabled.
The date edit is simpler in appearance than QDateEdit, but allows the user to navigate between fields using the left and right cursor keys, increment and decrement individual fields using the up and down cursor keys, and enter values directly using the number keys.
This property was introduced in Qt 4.3. -
What happens when dateEditEnabled is set to true is that you can input a date with your keyboard to change the date displayed on the calendar.
But you need to specify a bit what you mean with "modify the calendar widget" because I don't get whether this is what you want. The described behavior works for me.
-
I'm looking for the functionality that the calendar doesn't change the date when the user clicks on it. In effect is is readonly.
The other widget's in my dialog have .setReadOnly(bool) which does for those widgets exactly what I need.
I need this functionality because i have a dialog with two of these calendars one displays the old date which should never change, and the other is the one the user modifies.
-
Then TFabbri was right, you need to setEnabled(false) to the calendar widget. Something like
@
QCalendarWidget *cal = new QCalendarWidget();
cal->setEnabled(false);
cal->setDateEditEnabled(false);
@dateEditEnabled controls whether the calendar widget can be edited with keyboard, while enabled controls whether the widget accepts mouse events.
Notice that enabled is a property inherited from QWidget; that's why you couldn't find it in the doc page of QCalendarWidget.