[Kde-pim] QComboBox/ItemDelegate question
Stephen Kelly
steveire at gmail.com
Wed Nov 4 15:46:10 GMT 2009
Tobias Koenig wrote:
> Hej,
>
> I currently try to improve the 'display name' handling in KAddressBook
> by using a QComboBox instead of a QLineEdit to allow the user to select
> different types of the display name (e.g. normal, reverse, reverse with
> comma).
>
> So if the user has typed in 'Tobias Koenig Jr.' in the name edit, the
> display name combo box will contain the following entries (when opening
> the popup menu):
>
> | Tobias Koenig |
> | Tobias Koenig Jr. |
> | Koenig, Tobias |
> | Koenig Tobias |
> | |
> | Tobias Koenig |
>
> Now you might ask what is the difference between the first and the last
> entry and why is the last but one entry empty? To clarify that, I'd like
> to add descriptions in grey and italic font, so it would look like the
> following:
>
> | Tobias Koenig [Short Name] |
> | Tobias Koenig Jr. [Full Name] |
> | Koenig, Tobias [Reverse with Comma] |
> | Koenig Tobias [Reverse Name] |
> | [Organization] |
> | Tobias Koenig [Custom Name] |
>
> Adding the additional text in the proper format is no problem by applying
> an ItemDelegate to the QComboBox::view(), however though I reimplemented
> the QAbstractItemDelegate::sizeHint() method to return a fitting width,
> the popup menu is still too small, so half of the descriptions are cut
> away. It seems the width of the popup is aligned to the width of the
> combobox itself.
>
> Does one of you know a trick how the popup menu can be enforced to a given
> width?
Have you considered putting the data into a multi column list or table like
a QStandardItemModel and putting that model into the combobox? You should be
able to put the description in the second column. I do something similar in
kjots/kjotslinkdialog.cpp. I also create a view there to hide the extra
column, but that shouldn't be necessary for you.
tree = new QTreeView();
tree->setModel(proxyModel);
tree->expandAll();
tree->setColumnHidden(1, true);
hrefCombo->setModel(proxyModel);
hrefCombo->setView(tree);
I didn't try it for your case, but it might work or give you a better idea.
Steve.
>
> Ciao,
> Tobias
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list