Results 1 to 7 of 7

Thread: Editing in a QComboBox

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Editing in a QComboBox

    I am attempting to derive a class from QCombobox that has some specific properties. As yet, I can't get the line into a mode to be able to edit it. It appears that I can select a line in the list and can select the contents. Currently, the constructor looks like this.

    ListSelect::ListSelect( QWidget *parent )
    : QComboBox( parent )
    {
    setEditable( true );

    setInsertPolicy( QComboBox::InsertAtTop );
    }

    Question:
    How to I activate this control (focus in the edit field) so I can edit the information in the field?
    How do I select a portion of the string in the edit field?

    Thanks

  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: Editing in a QComboBox

    Quote Originally Posted by sterling View Post
    How to I activate this control (focus in the edit field) so I can edit the information in the field?
    Setting it to editable should have done that. What happens if you click into the line edit?

    Quote Originally Posted by sterling View Post
    How do I select a portion of the string in the edit field?
    Get the line edit and call its setSelection() method.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Henry Blue Heeler (4th January 2014)

  4. #3
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Editing in a QComboBox

    If I click into the line edit, the cursor does not show up anywhere. It's like the box never gets keyboard focus. If I set the cursor into an edit field, the vertical bar cursor shows up and I can type and navigate in the line. None of that behavior show up in the QComboBox. Typing does nothing when there is a blank selected or when there is actual text selected.

    S

  5. #4
    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: Editing in a QComboBox

    Very strange.
    Does this also happen if you take a normal QComboBox and set editable to true from outside?

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    sterling (4th January 2014)

  7. #5
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Editing in a QComboBox

    The combo box works just as expected.

    This is the definition of the derived class

    class ListSelect : public QComboBox
    {
    Q_OBJECT

    public:
    ListSelect(QWidget *parent = 0);
    ListSelect( void );
    ~ListSelect();
    };

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Editing in a QComboBox

    Is this complete code? Didn't you by any chance reimplement any code responsible for handling mouse events? How are you using the class? What properties do you set on the widget?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    sterling (4th January 2014)

  10. #7
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Editing in a QComboBox

    Found it. This was built from a custom widget that was put into design. I had set the focusPolicy to keyboard. Changing it to StrongFocus fixed the problem. I compared the ui_file entry for a ComboBox with mine and commented out properties until it worked. There are still other problems but those for later posts.

Similar Threads

  1. editing a image using QT
    By qtlearner123 in forum Newbie
    Replies: 5
    Last Post: 25th April 2012, 09:40
  2. Show QComboBox list while editing
    By radix07 in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 16:52
  3. Editing a file in Qt4
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2009, 09:33
  4. About Editing QtreeWidget
    By nikhilqt in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2008, 13:51
  5. Editing and adding entries to a QComboBox
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 29th May 2007, 17:13

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.