Problem with a custom popup inside QCompleter
-
I'm adding a custom QCompleter inside my application. I followed the various qt tutorials on using completion and until few minutes ago I had not particular problems. They started when I tried to customize the popup frame inside the QCompleter.
When I'm trying to write something the popup frame appears but it inside the visible frame (that has plausible size i.e. it is big enough in order to contain the right number of words it should display) no suggested words are visible until I'm passing for one time with mouse over the frame itself. After everything looks to work quite well. The strange thing is that when only the popup frame has been visualized the Qt framework doesn't detect any error. Instead when I pass over the frame and the content of popup becomes visible I got some error messages:@QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::save: Painter not active
QPainter::setClipRect: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::restore: Unbalanced save/restore
@This is an excerpt of my code with the important part:
@//custom popup: it inherits from QListView cause I'm interested on QCompleter::PopupCompletion.
MLAutoCompleterPopUp::MLAutoCompleterPopUp( QWidget* parent )
:QListView(parent)
{
}MLAutoCompleterPopUp::~MLAutoCompleterPopUp()
{
}bool MLAutoCompleterPopUp::event( QEvent *event )
{
if (event->type() == QEvent::ToolTip)
{
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QModelIndex indexid = indexAt(helpEvent->pos());
QModelIndex indexsign = indexid.sibling(indexid.row(),1);if (indexsign.isValid())
QToolTip::showText(helpEvent->globalPos(), indexsign.data().toString());
else
{
QToolTip::hideText();
event->ignore();
}
return true;
}
return QWidget::event(event);
}//Custom QCompleter
MLAutoCompleter::MLAutoCompleter( const MLScriptLanguage& synt,QWidget* parent )
:QCompleter(parent),syntax(synt)
{
setCompletionRole(Qt::DisplayRole);
setCaseSensitivity(Qt::CaseSensitive);
setCompletionMode(QCompleter::PopupCompletion);
MLAutoCompleterPopUp* pop = new MLAutoCompleterPopUp(parent);
setPopup(pop);
}//setup of the completer
void MLScriptEditor::setScriptLanguage( MLScriptLanguage* syntax )
{
if (syntax != NULL)
{
comp = new MLAutoCompleter(*synt,this);
comp->setWidget(this);
comp->setModel(synt->functionsLibrary());
connect(comp,SIGNAL(activated(const QString &)),this,SLOT(insertSuggestedWord( const QString &)));
connect(comp,SIGNAL(highlighted(const QModelIndex&)),comp,SLOT(changeCurrent(const QModelIndex&)));
}
}
@Every kind of suggestion is well accepted. Thanks!
-
Probably I found the problem but I need an help to fix it up:
@
MLAutoCompleterPopUp* pop = new MLAutoCompleterPopUp(parent);
setPopup(pop);
QWidget* view = popup()->viewport();
QPaintEngine* eng = view->paintEngine();
@QPaintEngine is NULL. How can I assign to my MLAutoCompleterPopUp a valid engine?
-
Ok I found the problem...and it was a stupid one.
In the last line of my MLAutoCompleterPopUp::event() I was calling the QWidget::event for all the events different from a tooltip request...but QListView reimplements his own event so I have to call it instead the one of QWidget.