PDA

View Full Version : How can I create a widget list as Qt Designer?



ricardo
28th April 2009, 17:12
I'd like to create in my main window something like a widget list (Qt desgigner has what I want) with different sections. Which componets or widgets should I use? (Can I do it without creating new components?)
With scrollbar and dockwindow (this one is easy to add). Filter would be nice. I guess is just another componet.

http://img524.imageshack.us/img524/1906/dgk56f49hj96rkgjb.jpg

Thanks a lot for your help.

aamer4yu
28th April 2009, 17:55
You could search the forum more. This had been discussed as far as I remember,

Hint 1 : QTreeView with delegates.
Hint 2: Dig in Designer code if available :)

ricardo
2nd May 2009, 00:23
You could search the forum more. This had been discussed as far as I remember,

Hint 1 : QTreeView with delegates.
Hint 2: Dig in Designer code if available :)

Thanks for reply. Unfortunately I'm a beginner so I don't understand it very well.

I only need several string lists with an icon every one, separeted by bold string (like the screenshot). Can I do it in a easy way? I don't know if I could delegate a class and add that functionality.

Thanks for help. Any idea?

Lykurg
2nd May 2009, 08:52
Thanks for reply. Unfortunately I'm a beginner so I don't understand it very well.
Then please use the Newbie section of this board. You are welcome.


I only need several string lists with an icon every one, separeted by bold string (like the screenshot). Can I do it in a easy way?
Yes, there is an easy way: QTreeView with delegates!


I don't know if I could delegate a class and add that functionality.
Look, the designer is a great tool, but it can't do anything for you. Still Qt is "part" of the C++ programming language, so you have to be a little knowledge of that if you want to work with it. For the delegate thing look in the docks, or as aamer4yu said ind the sources of designer.

ricardo
2nd May 2009, 08:56
OK. Thanks, I will read about that.

Well, this is what I was looking for:
http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-create-something-like-widget-box-in-qt-designer-14912.html

aamer4yu
3rd May 2009, 12:54
yea, using pushbutton looks good... but u have to make extra connections for buttons clicked... isnt it ?
With delegates you wont have to both so much...
Just made a simple delegate u can start with...

class TreeDelegate : public QItemDelegate
{
protected:
virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if(index.child(0,0).isValid())
{
painter->setPen(Qt::blue);
//painter->drawRect(option.rect);
QStyleOptionButton opt;
opt.rect = option.rect;
qApp->style()->drawControl(QStyle::CE_PushButton, &opt,painter);
}
QItemDelegate::paint(painter,option,index);
}
virtual void drawCheck ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, Qt::CheckState state ) const {};
};

You will need to call view->setItemDelegate(new TreeWidgetDelegate());
thats it.
also to achieve expand/collapse on single click like in designer, you can connect itemClicked signal to some function of yours..
Like ,,,

MainWindow::MainWindow()
{
ui.setupUi(this);
ui.treeWidget->expandAll();
connect(ui.treeWidget,SIGNAL(itemPressed(QTreeWidg etItem*,int)),this,SLOT(itemClicked(QTreeWidgetIte m*)));
ui.treeWidget->setItemDelegate(new TreeDelegate());
ui.treeWidget->setRootIsDecorated(false);
}
void MainWindow::itemClicked(QTreeWidgetItem* item)
{
item->setSelected(false);
item->setExpanded(!item->isExpanded());
}


One thing more to be noted is in Qt 4.5 designer has icon view too... so not sure if they have used tree widget for that... May be they might have used treewidget, with one parent one child... and the child must be QListWidget...;)