QComboBox/ItemDelegate question

View: New views
5 Messages — Rating Filter:   Alert me  

QComboBox/ItemDelegate question

by Bugzilla from tokoe@kde.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?

Ciao,
Tobias


_______________________________________________
KDE PIM mailing list kde-pim@...
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

signature.asc (205 bytes) Download Attachment

Re: QComboBox/ItemDelegate question

by Stephen Kelly-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

Re: QComboBox/ItemDelegate question

by Bugzilla from tokoe@kde.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 04, 2009 at 03:46:10PM +0000, Stephen Kelly wrote:
> Tobias Koenig wrote:
Hej,

> 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.
Unfortunately that doesn't fix the issue, that the popup menu is too thin,
with a QTableView the content of the items is only shown half...

Ciao,
Tobias


_______________________________________________
KDE PIM mailing list kde-pim@...
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

signature.asc (205 bytes) Download Attachment

Re: QComboBox/ItemDelegate question

by Bugzilla from tokoe@kde.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 04, 2009 at 07:17:27PM +0100, Tobias Koenig wrote:
> On Wed, Nov 04, 2009 at 03:46:10PM +0000, Stephen Kelly wrote:
Hej,

> > 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.
> Unfortunately that doesn't fix the issue, that the popup menu is too thin,
> with a QTableView the content of the items is only shown half...
I've implemented it the following way now:

  - install an event filter on QComboBox::view()->viewport()
  - listen for the 'QEvent::Show' event of the viewport
  - resize the viewport->parentWidget()->parentWidget() to the according size

not really convenient but it allows one to have a popup menu with a different
width than the combobox.

Ciao,
Tobias


_______________________________________________
KDE PIM mailing list kde-pim@...
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

signature.asc (205 bytes) Download Attachment

Re: QComboBox/ItemDelegate question

by Stephen Kelly-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tobias Koenig wrote:

> On Wed, Nov 04, 2009 at 07:17:27PM +0100, Tobias Koenig wrote:
>> On Wed, Nov 04, 2009 at 03:46:10PM +0000, Stephen Kelly wrote:
> Hej,
>
>> > 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.
>> Unfortunately that doesn't fix the issue, that the popup menu is too
>> thin, with a QTableView the content of the items is only shown half...
> I've implemented it the following way now:
>
>   - install an event filter on QComboBox::view()->viewport()
>   - listen for the 'QEvent::Show' event of the viewport
>   - resize the viewport->parentWidget()->parentWidget() to the according
>   size
>
> not really convenient but it allows one to have a popup menu with a
> different width than the combobox.
>
> Ciao,
> Tobias

Cool, thanks for the info.

Steve.


_______________________________________________
KDE PIM mailing list kde-pim@...
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/