Results 1 to 6 of 6

Thread: How to show all Combobox items when has the focus

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to show all Combobox items when has the focus

    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!
    Last edited by roseicollis; 11th February 2015 at 12:54.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to show all Combobox items when has the focus

    Quote Originally Posted by roseicollis View Post
    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

    Quote Originally Posted by roseicollis View Post
    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,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to show all Combobox items when has the focus

    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to show all Combobox items when has the focus

    Quote Originally Posted by roseicollis View Post
    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()?

  5. The following user says thank you to ChrisW67 for this useful post:

    roseicollis (18th February 2015)

  6. #5
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to show all Combobox items when has the focus

    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
    Qt Code:
    1. public:
    2. bool eventFilter(QObject *obj, QEvent *event);
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. ui->comboBox->installEventFilter(this);
    8. }
    9.  
    10.  
    11. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    12. {
    13. if(event->type() == QEvent::FocusIn)
    14. {
    15. QFocusEvent * tmp = static_cast<QFocusEvent *>(event);
    16. if(tmp->reason() == Qt::TabFocusReason || tmp->reason() == Qt::BacktabFocusReason)
    17. {
    18. ui->comboBox->showPopup();
    19. }
    20. }
    21. return false;
    22. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to StrikeByte for this useful post:

    roseicollis (18th February 2015)

  8. #6
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to show all Combobox items when has the focus

    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

Similar Threads

  1. Replies: 2
    Last Post: 4th June 2014, 10:20
  2. To show all items from combobox using wildcard character *
    By Sanjay123 in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2011, 15:40
  3. How to use Combobox to show a Ballon?
    By Bong.Da.City in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2010, 12:21
  4. QSqlRelationalDelegate (ComboBox) id on first show
    By janus in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 14:58
  5. Combobox with checkable items
    By qtneuling in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2008, 15:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.