Same here (64 bit linux, Qt 5.1.1).
Looks like some events are clearing the initial selection to default, because this works ok after the edit widget is shown:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDateTimeEdit>
#include <QPushButton>
Q_OBJECT
public:
{
connect(_btn, SIGNAL(clicked()), this, SLOT(nextSection()));
_edit.show();
_edit.
setDateTime(QDateTime::currentDateTimeUtc());
_edit.setDisplayFormat("yyyy-MM-dd hh:mm");
}
public slots:
void nextSection(){
static int s = 0;
s = (s+1)%3;
_edit.setCurrentSectionIndex(s);
_edit.setSelectedSection(_edit.currentSection());
}
private:
};
#endif
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDateTimeEdit>
#include <QPushButton>
class Widget : public QWidget{
Q_OBJECT
public:
Widget(QWidget * parent = NULL)
:QWidget(parent)
{
_btn = new QPushButton("next section",this);
connect(_btn, SIGNAL(clicked()), this, SLOT(nextSection()));
_edit.show();
_edit.setDateTime(QDateTime::currentDateTimeUtc());
_edit.setDisplayFormat("yyyy-MM-dd hh:mm");
}
public slots:
void nextSection(){
static int s = 0;
s = (s+1)%3;
_edit.setCurrentSectionIndex(s);
_edit.setSelectedSection(_edit.currentSection());
}
private:
QDateTimeEdit _edit;
QPushButton * _btn;
};
#endif
To copy to clipboard, switch view to plain text mode
When pressing the button, section is changed as expected.
Bookmarks