Results 1 to 5 of 5

Thread: Resize of ComboBox List Box

  1. #1
    Join Date
    Mar 2009
    Location
    Hyderabad, India
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Resize of ComboBox List Box

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resize of ComboBox List Box

    Use QComboBox::setView with your custom view with size grip.

    Or may be you can use QComboBox::showPopup to resize and show the view
    Last edited by aamer4yu; 2nd February 2010 at 08:25.

  3. #3
    Join Date
    Mar 2009
    Location
    Hyderabad, India
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resize of ComboBox List Box

    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.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resize of ComboBox List Box

    Well if you use setView function, you will need to make your own class. I tried the following -
    Qt Code:
    1. class MyListView : public QListView
    2. {
    3. QSizeGrip *grip;
    4. public:
    5. MyListView()
    6. {
    7. grip = new QSizeGrip(this);
    8. grip->resize(grip->sizeHint());
    9. }
    10. protected:
    11. void showEvent ( QShowEvent * event )
    12. {
    13. QListView::showEvent(event);
    14. grip->move(rect().bottomRight() - grip->rect().bottomRight());
    15. grip->raise();
    16. }
    17. void resizeEvent ( QResizeEvent * event )
    18. {
    19. QListView::resizeEvent(event);
    20. grip->move(rect().bottomRight() - grip->rect().bottomRight());
    21. grip->raise();
    22. }
    23. };
    To copy to clipboard, switch view to plain text mode 
    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

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resize of ComboBox List Box

    With scrollbar you can try using -
    Qt Code:
    1. QPoint delta;
    2. if(verticalScrollBar()->isVisible())
    3. delta = QPoint(verticalScrollBar()->width(),0);
    4. grip->move(rect().bottomRight() - grip->rect().bottomRight() - delta );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Help ComboBox
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 19:41
  2. ComboBox of bmp:s
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2008, 15:22
  3. Problem in displaying the ComboBox list
    By raghvendramisra in forum Qt Tools
    Replies: 4
    Last Post: 28th February 2008, 13:25
  4. Replies: 2
    Last Post: 22nd January 2008, 16:10
  5. locking the combobox
    By jayw710 in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2006, 16:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.