PDA

View Full Version : How to show all Combobox items when has the focus



roseicollis
11th February 2015, 11:39
Hi,

I am making a gui application with wizard+wizardpages in which interaction is 100% keyboard so the user moves around widgets and options using tab.

So i have a wizardpage with a line edit and a combobox wich has the next items : item1, item2, item3 and item4.

What I have is: When user enters this page, the focus is on line edit, so he can write there and if he tab, he goes to the combobox which is showing item1 by default. If he press down arrow, combobox shows item2. The problem here is that with this way the user don't know all the options of the combobox unless he press down until the last option.

What I want is: When user enters, the focus is on line edit (until here: ok). BUT then, when he tabs and go to combobox, I want this combobox to show all options (as when you click with the mouse, that you can see all the options in a list). I've been looking for dropdown options and views but couln't find one that makes that... do you know if there is any option to do that?

And another question: by default in qt, when you have the focus on a widget like a button or a line edit or a combobox.... there is a thin blue border to mark it... is there any way to change that style when focus? I want to change that border to orange or disable it and change the combobox background color when it has the focus for example...

Thank you so much!

anda_skoa
11th February 2015, 13:08
What I want is: When user enters, the focus is on line edit (until here: ok). BUT then, when he tabs and go to combobox, I want this combobox to show all options (as when you click with the mouse, that you can see all the options in a list). I've been looking for dropdown options and views but couln't find one that makes that... do you know if there is any option to do that?


http://doc.qt.io/qt-5/qcombobox.html#showPopup


And another question: by default in qt, when you have the focus on a widget like a button or a line edit or a combobox.... there is a thin blue border to mark it... is there any way to change that style when focus? I want to change that border to orange or disable it and change the combobox background color when it has the focus for example...

That is all handled by the current widget style, you can always create your own.

Cheers,
_

roseicollis
11th February 2015, 16:16
Hi,

I thought that showPopup must help but it does nothing... I tried putting myCombobox->showPopup(); on the constructor of that wizardpage, the initializepage() and the eventfilter() but it does nothing.


Thanks.

ChrisW67
11th February 2015, 20:15
I tried putting myCombobox->showPopup();

No visible combo box exists at this point, and certainly not one with the focus.

on the constructor of that wizardpage,
Ditto

the initializepage()
"This virtual function is called by QWizard::initializePage() to prepare the page just before it is shown..." Emphasis mine.

and the eventfilter() but it does nothing.
We have no idea which event filter this might be, or what you have done with it. So it is hard to say much more about this.

Had you looked at the combo box's focusInEvent()?

StrikeByte
13th February 2015, 10:23
You can install a eventFilter on the combobox and react when it is a focus in event

or tell the user to press the spacebar (default behaviour for comboboxes)

.h


public:
bool eventFilter(QObject *obj, QEvent *event);


.cpp


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

ui->comboBox->installEventFilter(this);
}


bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::FocusIn)
{
QFocusEvent * tmp = static_cast<QFocusEvent *>(event);
if(tmp->reason() == Qt::TabFocusReason || tmp->reason() == Qt::BacktabFocusReason)
{
ui->comboBox->showPopup();
}
}
return false;
}

roseicollis
18th February 2015, 08:19
You can install a eventFilter on the combobox and react when it is a focus in event

or tell the user to press the spacebar (default behaviour for comboboxes)

Hi, thanks for your reply StrikeByte. Your code works well (and thanks to it I remembered that I had to installEventFilter -.-'' somthing I always forget) But it showpopup when it has the focus AND I press spacebar.... It doesn't appear only because it has the focus :S

ChrisW67, thanks for your reply. I understand what you mean :)