PDA

View Full Version : Highlighting selected section on QDateTimeEdit



Yorma
2nd March 2006, 11:19
I have subclassed QDateTimeEdit for viewing the current date and time. User has also ability to change the date/time. As my system has no mouse I was wondering how do I set a specific section as selected (highlighted or similar so the user can see which section he is about to change). Key presses are used for selecting the section to be changed on QDateTimeEdit and for changing the current section value.

The problem is that user cant see which section is selected, at least not until he changes the value and the section where QDateTimeEdit::setCurrentSection() is set to be pointing gets highlighted.
The logic on changing the date/time is ok now, but I dont know how to set the section selected for user point of view, as in the way it gets higlighted when you change the value by stepUp(), stepDown() or stepBy().

Surely I could just do



stepUp();
stepDown();


to get the section highlighted, but that would mess up setting the dates when it's 1st or last day of the month and wrapping is set to false. And If i set the wrapping on, it only works when decreasing values (on date field: 2->1->31->30), not when they are increased (on datefield: 30->31->31->31).

I thought that QDateTimeEdit::setCurrentSection() would do the trick of highlighting the current section, but I was wrong.

I'm using Qt 4.1 on linux.

Yorma
3rd March 2006, 07:05
I tried to figure out what happens when you call stepBy() from Qt's source code, but I didn't find what causes the currentSelection field to be highlighted. I think this is something simple I just haven't been able to figure out?

jacek
3rd March 2006, 10:25
void QAbstractSpinBox::stepUp()
{
stepBy(1);
}

void QAbstractSpinBox::stepBy(int steps)
{
// ...
selectAll();
}

void QDateTimeEdit::stepBy(int steps)
{
// ...
d->setSelected(d->currentSectionIndex);
}

void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)
{
if (specialValue()) {
edit->selectAll();
} else {
// ...
if (forward) {
edit->setSelection(sectionPos(node), size);
} else {
edit->setSelection(sectionPos(node) + size, -size);
}
}
}
Unfortunately setSelected() is in private part of the QDateTimeEdit implementation, so you can't use it directly.

Bebert218
16th July 2009, 03:24
I'm sorry to bring that thread up, but I actually have the same problem right now.
Meanwhile, it seems that a couple of functions were added to Qt, of which setSelectedSection,
but no matter what I do, the cursor always stays on the first section until the user interacts with the GUI. :confused:
Did anybody get the same behavior here ?

dopestuff
3rd May 2013, 12:03
Unless its been fixed in a recent release (probably not but I havent tried - cant afford the disk space for more than 2 parallel versions of qt)...

Then, what you describe should probably be classified as a long time bug in Qt, that is, an inconsistency between the direct keyboard editing and software only control.

I usually steer well clear from GUIs and Commodity software...

Anyway so that you know, none of the previous suggestions will give you the correct behaviour and
the solution is not going to be as obvious as anyone has previously attempted to point out.
You are going to have to do what I did and get well acquainted with debugging the Qt Libraries.
In the end I made a very small fix/workaround in the Qt Libraries to get this to work.

Since I think Commodity/Free software and lack of regulation hurts the working Software Professional I will not post my version of the fix/workaround in the public domain. I will
leave that to some other person that believes doing work for free somehow greatly
improves their fiscal and career prospects in the "commodity software employers" buyers
market.