PDA

View Full Version : Resize of ComboBox List Box



sivollu
2nd February 2010, 06:41
Hi,

I am trying to enlarge the size of ComboBox Listbox. I mean, for QDialog we have sizeGripEnabled(true) function, which will give us the sizegrip widget at bottom right corner, as same i want for QComboBox Listbox. I tried with the QSizeGrip class but it was not working. I want the sizegrip widget at bottom right corner of the combobox listbox.

Please give an idea to proceed.



Thanks in advance,
Siva Rama Krishna.

aamer4yu
2nd February 2010, 07:09
Use QComboBox::setView with your custom view with size grip.

Or may be you can use QComboBox::showPopup to resize and show the view

sivollu
2nd February 2010, 09:07
Hi,

I used QComboBox::view() function. I wrote the code as follows.

mcmbUnit = new QComboBox();
mcmbUnit->setFixedWidth(140);
mcmbUnit->addItem("A");
mcmbUnit->addItem("B");
mcmbUnit->addItem("C");
QSizeGrip* sGrip = new QSizeGrip(mcmbUnit->view());

I was getting the SigeGrip widget at the Top Left corner of the ListBox.

I was unable to use setView() and showPopUp() functions.

Can you just bit clear if possible.

aamer4yu
2nd February 2010, 10:15
Well if you use setView function, you will need to make your own class. I tried the following -

class MyListView : public QListView
{
QSizeGrip *grip;
public:
MyListView()
{
grip = new QSizeGrip(this);
grip->resize(grip->sizeHint());
}
protected:
void showEvent ( QShowEvent * event )
{
QListView::showEvent(event);
grip->move(rect().bottomRight() - grip->rect().bottomRight());
grip->raise();
}
void resizeEvent ( QResizeEvent * event )
{
QListView::resizeEvent(event);
grip->move(rect().bottomRight() - grip->rect().bottomRight());
grip->raise();
}
};

You will need to set something like - comboBox->setView(new MyListView());
I could get the grip on bottom right. I refered to QDialog code how they used QSizeGrip.
But theres a problem, the grip gets hidden after resize when theres a scrollbar. May be you can work on it.

If you had to use showPopup(), you will need to subclass QComboBox, resize the view in it and then call show. You can search in QComboBox::showPopup what it does.

Hope this helps :)

aamer4yu
2nd February 2010, 10:57
With scrollbar you can try using -


QPoint delta;
if(verticalScrollBar()->isVisible())
delta = QPoint(verticalScrollBar()->width(),0);
grip->move(rect().bottomRight() - grip->rect().bottomRight() - delta );