PDA

View Full Version : Editing in a QComboBox



sterling
4th January 2014, 02:29
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

anda_skoa
4th January 2014, 11:35
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?



How do I select a portion of the string in the edit field?

Get the line edit and call its setSelection() method.

Cheers,
_

sterling
4th January 2014, 17:08
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

anda_skoa
4th January 2014, 17:54
Very strange.
Does this also happen if you take a normal QComboBox and set editable to true from outside?

Cheers,
_

sterling
4th January 2014, 19:07
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();
};

wysota
4th January 2014, 20:49
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?

sterling
4th January 2014, 23:17
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.