PDA

View Full Version : Removing the branches from QListVew...



ct
14th February 2006, 06:55
I have spent a lot of time trying to remove the branches off the listview but have been unsuccesfull till now. I am usin free qt 3.3.4. I guess there is a virtual function called paintBrances(,,,,) with several parameters...Does anyone know how we can apply the QPainter along with other parametere of this function so that the branches could be removed..
I would have tried harder...but I don't want to waste much time in it..so if anyone has already removed the dotted branches of the Listview please help..

wysota
14th February 2006, 10:24
Reimplement that function and leave it blank. It should work :)

ct
14th February 2006, 18:00
Well.. I tried and it didn't work..
I first tried wtih
void ListView::drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch )
{

}

which had no effect... and also tried with the paintBranches function...but no luck..

Well..it seems that I had to change the Wdiget style through setStyle...digging into it right now :)

wysota
14th February 2006, 20:41
I don't see a paintBranches method in Qt3 QListView...

Aa... it's in QListViewItem... Reimplementing it and leaving it blank should certainly work...

ct
14th February 2006, 21:32
well I don't like pasting codes...but I don't know what I am doing wrong. The code seems to compile correctly but the branches are still there...here is the code..I have made QListView in the Qt Designer.

void ListView::init()
{
mainList->setRootIsDecorated(TRUE);
QHeader *head=mainList->header();
head->hide();
// mainList->setTreeStepSize(40);
setGroups("A",10);
setGroups("B",10);
setGroups("C",20);
setGroups("D",20);

}


void ListView::setGroups(QString label,int items)
{

QListViewItem *grpItem=new QListViewItem(mainList,label);
mainList->setTreeStepSize(25);
// mainList->setStyle(QStyle::SC_ListViewBranch);
for(int i=0;i<items;i++)
{
new QListViewItem(grpItem,"Listings");
}

}

void ListView::paintBranches ( QPainter * p, const QColorGroup & cg, int w, int y, int h )
{
}


even tried with
void paintBranches( QPainter * p, const QColorGroup & cg, int w, int y, int h )
{
}

compiled correctly but no desired output..

well I tried drawContentsOffset() in the similar manner and in the manual it says that that function of QListView will call paintBranches..in either case no luck..
Do I need to be using QStyle for this ??

wysota
14th February 2006, 21:50
But paintBranches should be reimplemented in the item not in the view!


class MyListViewItem : public QListViewItem{
//...
void paintBranches ( QPainter * p, const QColorGroup & cg, int w, int y, int h ){}
};

//...
void ListView::setGroups(QString label,int items)
{
MyListViewItem *grpItem=new MyListViewItem(mainList,label);
//...

ct
15th February 2006, 18:51
I didn't think it would take this much of time..however finally I got the branches to be removed . But the problem isn't solved...it seems that the ListView is not repainting it in somewhat and I have tried using it at various places but all attempts failed..

I have added a picture which might give a better picture.(The unwanted part that hasn't been repainted has been circled with red).

However, if I minimize the whole application and then maximize then the widget gets repainted again...

Also if someone might help to remove the still remaining dotted lines that are in the list..(refer to the picture)

ct
16th February 2006, 17:54
Also could anyone tell the functions that are called when a mainWindow is minimized and maximized. If I could reimplement the painting functions that are called during maximization of a widget may be I could solve this problem..

wysota
16th February 2006, 23:11
Also could anyone tell the functions that are called when a mainWindow is minimized and maximized. If I could reimplement the painting functions that are called during maximization of a widget may be I could solve this problem..

QWidget::paintEvent() :)

ct
19th February 2006, 16:09
Finally, got rid of all the branches in the ListView :) . By creating a style and re-implementing the drawComplexControl function as I have done below we can easily remove the branches.



#include <qwindowsstyle.h>
#include <qstyle.h>
#include<qpainter.h>
#include<qpixmap.h>
#include<qlistview.h>

class ListStyle:public QWindowsStyle
{
Q_OBJECT

public:
ListStyle();
~ListStyle();

void drawComplexControl ( ComplexControl control, QPainter * p, const QWidget * widget, const QRect & r, const QColorGroup & cg, SFlags how = Style_Default, SCFlags sub = SC_All, SCFlags subActive = SC_None, const QStyleOption & opt = QStyleOption::Default ) const ;
private:
// Disabled copy constructor and operator=
ListStyle( const ListStyle & );
ListStyle& operator=( const ListStyle & );
};



ListStyle::ListStyle()
{
}


ListStyle::~ListStyle()
{


}

void ListStyle::drawComplexControl ( ComplexControl control, QPainter * p,
const QWidget * widget, const QRect & r, const QColorGroup & cg,
SFlags how , SCFlags sub ,
SCFlags subActive , const QStyleOption & opt ) const
{
if((sub & SC_ListViewBranch))
{

}
else
QWindowsStyle::drawComplexControl(control,p,widget ,r,cg,how,sub,subActive,opt);
}


after making this we just need to set the style for the listview widget like
myListView->setStyle(new ListStyle());


Just posted it so that no one ever has to waste a lotttt of time as I did digging into this minor detail....
:)

jatoro46
30th March 2006, 01:05
Hi,

I am having a similar problem... I don't want to draw the dotted branch lines, but I do want to draw the little collapse/expand square next to the items that contain children... does anyone have any ideas on how I can accomplish that?

Thanks!

SkripT
30th March 2006, 13:48
Hi,

I am having a similar problem... I don't want to draw the dotted branch lines, but I do want to draw the little collapse/expand square next to the items that contain children... does anyone have any ideas on how I can accomplish that?

Thanks!

take a look at this thread
http://www.qtcentre.org/forum/showthread.php?t=1095&highlight=branches

jatoro46
30th March 2006, 20:45
thank you for your input. Unfortunately, I am using Qt 3.3.5 and this example is only good for Qt4. I appreciate the suggestion though.
:o

ct
9th April 2006, 05:57
Hi,

I am having a similar problem... I don't want to draw the dotted branch lines, but I do want to draw the little collapse/expand square next to the items that contain children... does anyone have any ideas on how I can accomplish that?

Thanks!



well I have already pasted the code for removing ALL the branches. Now as for the square is concerned, you can create a small + and - square pixmap and put the pixmap on QListViewItem. Then all you need to do is catch a single or double click on the QListViewItem and change the pixmap according to whether the item is open or closed. Qt 3.3.4 has those functions I guess (and 3.3.5 will have it if I am not wrong). Now make those QListViewItem having +,- pixmaps as parents for all other QListViewItems and you are set to go..