How to see start of text in a narrow combo box?
-
I have a QComboBox which I have populated with addItem() repeatedly, and then selected an item with setCurrentIndex(). The trouble is that some of the text is wider than the width of the box and it shows the text moved to the left so the right-hand-side is visible. I want the text in the edit box to be positioned the same as the text in the drop-down box (so the start of text is visible on the left-hand-side, and any oversized text unseen on the right).
Some suggested reasoning: I think it may be trying to ensure the cursor is visible, after leaving the cursor at the end. But I have tried using setCursorPosition(1) but there is no such function in QComboBox.
-
I have noticed that the width of the QComboBox tends to be large enough to hold all the contents if allowed to grow. If possible, giving it more room would be one option.
You might be able to put the full text of the line in a popup (context help). When you hover over a particular item that you cannot see completely a popup will appear showing the full text contents. I am not sure how to do this in Qt off the top of my head but I know it can be done (i.e. VitrualBox shows context help when you hover over items).
Another option might be to override the paintEvent() for the combo box items. This is more work but will definitely allow you to present the data in any way you want to.
You could shrink the size of the text (items that are too big for the current size) by changing the font size of the combo box item. This might be ugly though.
-
Thank you Rondog for your suggestions.
I don't want to move the right side of the dialog box so the combo box grows. I don't want to hover over the item to see it in full in a popup. I don't want to reduce the size of the font so it will fit (just on some long items). I really want the text in the edit box to be positioned the same as the text in the drop-down box (so the start of text is visible on the left-hand-side, and any oversized text unseen on the right).
Thank you Rondog for your suggestions.
I don't want to move the right side of the dialog box so the combo box grows. I don't want to hover over the item to see it in full in a popup. I don't want to reduce the size of the font so it will fit (just on some long items). I really want the text in the edit box to be positioned the same as the text in the drop-down box (so the start of text is visible on the left-hand-side, and any oversized text unseen on the right).
I'm wondering if it's possible to move the cursor to the beginning of the line in the line edit, so Qt will move the text to the right so as to make the cursor visible. I'm told a combo box is a combination of a line edit and a list box but I don't see how to get access to the line edit functions.