| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 4 | |
I have created my delegate class. That is his implementation:
QWidget *DonorDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QComboBox *combobox = new QComboBox(parent);
QMapIterator<QString, int> i(m_map);
while (i.hasNext())
{
i.next();
combobox->addItem(i.key(), i.value());
}
combobox->installEventFilter(const_cast<DonorDelegate*>(this));
return combobox;
}
I create it with this code:
QMap<QString, int> map;
QSqlQuery query;
query.exec("select ...");
while (query.next())
{
map[query.value(1).toString() + " " +
query.value(2).toString() + " " +
query.value(3).toString() + " " +
query.value(4).toString() + " " +
query.value(5).toString()] = query.value(0).toInt();
}
packetsTableView->setItemDelegateForColumn(packets_donor, new
DonorDelegate(map))
I have some questions.
1. When I do
packetsTableView->resizeColumnsToContents()
the column width become about 10-20 px. That is not enough to represent 5
strings.
How I must get correct behaviour?
2. What should I do that when I open ComboBox its width become the width of
the largest element?
--
[ signature omitted ]
> 2. What should I do that when I open ComboBox its width become the width > of the largest element? Maybe what you're looking for is setting setSizeAdjustPolicy(QComboBox::AdjustToContents); to your combobox? --stathis -- [ signature omitted ]
2007/7/19, Stathis <stathis@xxxxxxxxxxxxxxxx>: > > > Maybe what you're looking for is setting > setSizeAdjustPolicy(QComboBox::AdjustToContents); > to your combobox? > > --stathis > That setting already set to this value. I will try to describe my situation better. e.g. combobox have full names. It represent my name like "Yurko...lav". Can I do so that when I open combobox my name represents fully like "Yurkov Vyacheslav"? -- [ signature omitted ]
Yurkov Vyacheslav wrote: > 2007/7/19, Stathis <stathis@xxxxxxxxxxxxxxxx > <mailto:stathis@xxxxxxxxxxxxxxxx>>: > > > Maybe what you're looking for is setting > setSizeAdjustPolicy(QComboBox::AdjustToContents); > to your combobox? > > --stathis > > That setting already set to this value. I will try to describe my > situation better. > e.g. combobox have full names. It represent my name like "Yurko...lav". > Can I do so that when I open combobox my name represents fully like > "Yurkov Vyacheslav"? > > -- > Yurkov Vyacheslav <UVV-mail@xxxxxxxxx> Electronic Engineer > Norilsk Tel: +79069001870 > > Automation of controling systems and technologic processes > Open Joint Stock Company MMC Norilsk Nickel, brass works I set the list in the combobox (after the adjusttocontents policy setup) via the setModel command and I don't have this problem. It seems to have a problem adjusting the popup menu in the designer too, even when switching on QComboBox::AdjustToContents. Maybe you want to isolate your problems in a compilable example so others can probably take a look also, I am not sure what could be wrong. --st -- [ signature omitted ]
2007/7/20, Stathis <stathis@xxxxxxxxxxxxxxxx>: > > I set the list in the combobox (after the adjusttocontents policy setup) > via the setModel command and I don't have this > problem. It seems to have a problem adjusting the popup menu in the > designer too, even when switching on > QComboBox::AdjustToContents. Maybe you want to isolate your problems in a > compilable example so others can probably take > a look also, I am not sure what could be wrong. > > --st > Well, there are two problems that I have described before in included file. 1. To look at first problem you should double click on donor field. Problem related to function resizeColumnsToContents() 2. When you press Enter key on existing record you'll see the second combobox problem. When you open it you'll not see the full name. Any suggestions?
Attachment:
Attachment:
comboBoxAutoAdjust.tar.bz2
Description: BZip2 compressed data
Message 6 in thread
Yurkov Vyacheslav wrote:
>
> 2007/7/20, Stathis <stathis@xxxxxxxxxxxxxxxx
> <mailto:stathis@xxxxxxxxxxxxxxxx>>:
>
> I set the list in the combobox (after the adjusttocontents policy
> setup) via the setModel command and I don't have this
> problem. It seems to have a problem adjusting the popup menu in the
> designer too, even when switching on
> QComboBox::AdjustToContents. Maybe you want to isolate your problems
> in a compilable example so others can probably take
> a look also, I am not sure what could be wrong.
>
> --st
>
> Well, there are two problems that I have described before in included file.
> 1. To look at first problem you should double click on donor field.
> Problem related to function resizeColumnsToContents()
> 2. When you press Enter key on existing record you'll see the second
> combobox problem. When you open it you'll not see the full name.
> Any suggestions?
Are you trying to stretch your horizontal header to occupy the whole space? You can do this if so:
packetsTableView->horizontalHeader()->setStretchLastSection(true);
packetsTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Now if there is not enough space I don't know what you would expect the widget to do with the text apart from
compressing it with ... for the headers
Also you could set the size of individual delegates by implementing the following function on your delegate:
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
of you could resize the combobox in setEditorData, e.g. combobox->resize(200,25); ? This has the effect of the editor to
span beyond the cell it encloses it originally.
For the other problem with the combobox's popup expansion, as I said I use a custom model, in which I provide a
display/edit/tooltip roles only. once I set it, it works. I don't know why yours doesn't, sorry.
--stathis
--
[ signature omitted ]