Results 1 to 5 of 5

Thread: Is it possible to add a widget into QComboBox ?

  1. #1
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Question Is it possible to add a widget into QComboBox ?

    Hi All,

    I suppose to add a widget into QComboBox to clear all the items in it,
    just like google toolbar search box, inside google toolbar search box there is
    an special item named "clear history search" .
    Can QT4 do that?

    Thanks advance for your help.
    hb

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to add a widget into QComboBox ?

    you should subclass QComboBox and add such functionality.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    hashb (27th October 2009)

  4. #3
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Re: Is it possible to add a widget into QComboBox ?

    Hi Spirit,

    Thanks for the clue,I'll try to do that.

    Best regards,
    hb

  5. #4
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Re: Is it possible to add a widget into QComboBox ?

    I implement a "google-search bar" as below,hope it will help others

    Qt Code:
    1. //mytoolbar.h
    2. #ifndef MYTOOLBAR_
    3. #include <QComboBox>
    4. #include <QPushButton>
    5. #include <QListWidget>
    6.  
    7. class myQListWidget:public QListWidget
    8. {
    9. public:
    10. myQListWidget(QWidget * parent = 0 ):QListWidget(parent)
    11. {
    12. setViewportMargins(0,0,0,30); //we'll put "clear history" button in the bottom margin
    13. }
    14. };
    15. class myToolBar:public QComboBox
    16. {
    17. public:
    18. myToolBar(QWidget * parent = 0);
    19. void showPopup ();
    20. void hidePopup ();
    21. private:
    22. myQListWidget *te_;
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mytoolbar.h"
    2.  
    3. myToolBar::myToolBar(QWidget * parent ):QComboBox(parent)
    4. {
    5. setStyleSheet("QPushButton {text-align:center;color:blue;text-decoration:underline;font-family:arial; background-color:#d4d0c8; }");
    6. setEditable(true);
    7. setFrame(false);
    8. resize(300,size().height());
    9.  
    10. te_ = new myQListWidget(this);
    11. setView(te_);
    12. setModel(te_->model());
    13. te_->viewport()->setBackgroundRole(backgroundRole()); //change the background color of popup list
    14.  
    15.  
    16. bt_ = new QPushButton("clear hisroty",view());
    17. bt_->setFlat(true);
    18. bt_->setVisible(false);
    19.  
    20. connect(bt_,SIGNAL(clicked(bool)),this,SLOT(clear()));
    21.  
    22. }
    23.  
    24. void myToolBar::showPopup ()
    25. {
    26. QComboBox::showPopup ();
    27. bt_->setVisible(true);
    28. //move button to right-down corner
    29. QRect qRect(view()->geometry());
    30. int iXpos=qRect.width()-bt_->width();
    31. int iYpos=qRect.height()-bt_->height();
    32. bt_->move(iXpos,iYpos);
    33.  
    34. }
    35. void myToolBar::hidePopup ()
    36. {
    37. QComboBox::hidePopup ();
    38. bt_->setVisible(false);
    39. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Re: Is it possible to add a widget into QComboBox ?


Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 08:06
  2. Widget Focus
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2008, 11:22
  3. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 23:29
  4. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 21:39
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 11:35

Tags for this Thread

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.