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
Re: Is it possible to add a widget into QComboBox ?
you should subclass QComboBox and add such functionality.
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
Re: Is it possible to add a widget into QComboBox ?
I implement a "google-search bar" as below,hope it will help others :)
Code:
//mytoolbar.h
#ifndef MYTOOLBAR_
#include <QComboBox>
#include <QPushButton>
#include <QListWidget>
{
public:
{
setViewportMargins(0,0,0,30); //we'll put "clear history" button in the bottom margin
}
};
{
public:
void showPopup ();
void hidePopup ();
private:
myQListWidget *te_;
};
#endif
Code:
#include "mytoolbar.h"
{
setStyleSheet("QPushButton {text-align:center;color:blue;text-decoration:underline;font-family:arial; background-color:#d4d0c8; }");
setEditable(true);
setFrame(false);
resize(300,size().height());
te_ = new myQListWidget(this);
setView(te_);
setModel(te_->model());
te_->viewport()->setBackgroundRole(backgroundRole()); //change the background color of popup list
bt_->setFlat(true);
bt_->setVisible(false);
connect(bt_,SIGNAL(clicked(bool)),this,SLOT(clear()));
}
void myToolBar::showPopup ()
{
bt_->setVisible(true);
//move button to right-down corner
QRect qRect
(view
()->geometry
());
int iXpos=qRect.width()-bt_->width();
int iYpos=qRect.height()-bt_->height();
bt_->move(iXpos,iYpos);
}
void myToolBar::hidePopup ()
{
bt_->setVisible(false);
}
Re: Is it possible to add a widget into QComboBox ?