ReImplement showPopup for my QComboBOx
Hi,
I think that the problem is easy, but i don't know how to process for this:
I just want to reimplement QComboBox::showPopup() in my new class that inherit from QComboBox, but I want to reuse the given code and just add one line.
I can't because:
Quote:
`QComboBoxPrivate* QComboBox::d_func()' is private
mycombobox.cpp:24: error: within this context
mycombobox.cpp:31: error: invalid use of undefined type `struct QAbstractItemView'
d:/Outils/Qt/qt/qt/include/QtGui/../../src/gui/itemviews/qabstractitemdelegate.h:59: error: forward declaration of `struct QAbstractItemView'
mycombobox.cpp:31: error: invalid use of undefined type `struct QComboBoxPrivate'
d:/Outils/Qt/qt/qt/include/QtGui/../../src/gui/widgets/qcombobox.h:60: error: forward declaration of `struct QComboBoxPrivate'
mycombobox.cpp:32: error: `QItemSelectionModel' has not been declared
mycombobox.cpp:32: error: `ClearAndSelect' was not declared in this scope
mycombobox.cpp:33: error: invalid use of undefined type `struct QComboBoxPrivate'
...
My code:
Code:
#include <QComboBox>
{
public:
virtual void showPopup();
};
/*!
Displays the list of items in the combobox. If the list is empty
then the no items will be shown.
If you reimplement this function to show a custom pop-up, make
sure you call hidePopup() to reset the internal state.
*/
void MyComboBox::showPopup()
{
// i just try this part of the code
if (count() <= 0)
return;
QStyle * const style
= this
->style
();
view()->selectionModel()->setCurrentIndex(d->currentIndex,
QComboBoxPrivateContainer* container = d->viewContainer();
/* ... */
How could i reuse the code for this method please ? :confused:
Thanks.
Re: ReImplement showPopup for my QComboBOx
Re: ReImplement showPopup for my QComboBOx
In general you can't. You should use QComboBox::view() and QComboBox::setView() instead.
Re: ReImplement showPopup for my QComboBOx
Quote:
Originally Posted by
wysota
Thanks !!! ;)
I just use view() :
Code:
void MyComboBox::showPopup()
{
view()->move(view()->x(), view()->y() - view()->height()/2);
}
I reimplement the method becasue I would like to show the items 1, 2 and 3 in a view above the QComboBox button, and the items 4, 5 and 6 below the button in a other view.
How could i do that ? : create two QListWidget and separate the QComboBox view in the two QListWidget ? :confused:
Thanks again
Re: ReImplement showPopup for my QComboBOx
I think all you need to do is to move the popup up (change its geometry) using something like:
Code:
view()->window()->move(...);
Re: ReImplement showPopup for my QComboBOx
It's an old thread, but the problem is still there. I needed some time to see the obvious: you have to call the base class "showPopup" before moving the popup item. This works well:
Code:
void MyQComboBox::showPopup() {
QWidget *popup
= this
->findChild<QFrame
*>
();
popup->move(popup->x(),popup->y()-this->height()-popup->height());
}