PDA

View Full Version : QLayoutPrivate issue



gimel
26th November 2008, 08:48
I am trying to extend the Qt example FlowLayout to include the insertWidgetAt(int position, QWidget* w) method.

I wrote (borrowed the code from QBoxLayout):


//public:
void FlowLayout::insertWidgetAt(int pos,QWidget *w){
addChildWidget(w);
insertItem(pos,QLayoutPrivate::createWidgetItem(th is, w)); //***
invalidate();
}

//private:
void FlowLayout::insertItem(int pos,QLayoutItem *item){
itemList.insert(pos,item);
}


At the line marked with //***, gcc gives "incomplete type `QLayoutPrivate' used in nested name specifier" error. What should I do to implement the method?

spirit
26th November 2008, 08:56
use QWidgetItem insted of QLayoutPrivate::createWidgetItem.
i.e.


insertItem(pos,QWidgetItem(w));

gimel
26th November 2008, 09:02
I resolved this issue by


#include <QtGui/private/qlayout_p.h>

If this will not work, I'll try your solution.

spirit
26th November 2008, 09:23
it is bad idea to use Qt's internal code.

gimel
26th November 2008, 14:45
Indeed! Thank you.

levi
20th May 2011, 09:27
I'm trying to do the exact same thing. This thread is rather old, but I would be very happy to know how you solved this. I'm struggling with getting the suggestion from "spirit" to work.

thegecko
29th May 2013, 19:57
You also need to store the widget using addChildWidget(). So the additional functions should look like the following:


void FlowLayout::insertItem(int index, QLayoutItem *item)
{
itemList.insert(index, item);
}

void FlowLayout::insertWidget(int index, QWidget *widget)
{
addChildWidget(widget);
QWidgetItem *item = new QWidgetItem(widget);
insertItem(index, item);
}


P.S. this works for me.