PDA

View Full Version : how i can add image in verticalHeaderview() of tableWidget



jyoti
26th December 2006, 12:50
hi all
i m using QT4.2 on MacOs .
i can add image directly by designer
but i actully wanna this view(attached) by coding..so than i can resize the pixmap which is placed there ...means i want to add image more large on this verticalHeader

i have code for this row items


int row=0;
int RowCount=0;
row=tableWidget->rowCount();
tableWidget->setRowCount(row+1);
QTableWidgetItem *item=new QTableWidgetItem("Nikon");
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
tableWidget->setItem(RowCount,0,item);

QTableWidgetItem *item1=new QTableWidgetItem("Png ");
tableWidget->setItem(RowCount,1,item1);

plz do suggest me as soon as possible,its urgent

wysota
26th December 2006, 15:33
tableWidget->verticalHeaderItem(0)->setData(Qt::DecorationRole, QPixmap("..."));

Is that what you want?

jyoti
27th December 2006, 07:58
thanks wysota...but its already come with my code like

tableWidget->verticalHeaderItem(0)->setIcon(QIcon(":/images/nikon.png"));

now i wanna resize the row width as per contents size increases
like if icon size increased the size of row width should be increase
but by this neither size is increased nor row cell width increased...

can u plz suggest me how this can be implement
setVerticalHeader ( QHeaderView * header )
will it work for it ...and how??

i m trying to use it like
QHeaderView *header=new QHeaderView(Qt::Vertical,tableWidget);
header->setResizeMode(QHeaderView::Stretch);
tableWidget->verticalHeaderItem(0)->setIcon(QIcon(":/images/nikon.png"));
tableWidget->setVerticalHeader(header);


even this is not working well its not stretching the row cell


plz do help me as soon as possible

wysota
27th December 2006, 11:03
Set the resize mode to QHeaderView::ResizeToContents and make sure a proper size hint is returned for the item.

I'm still not sure if it's what you want... Maybe you should just reimplement QHeaderView::sectionSizeHint?

jyoti
27th December 2006, 12:48
thanks for replying
but my problem is i want to increase the size of icon or image which is placed in all verticalheader cells
i want like(see attachment) this but in this form the icon is very small i want that icon should be as large as cell height is...and cell width(where icon is placed) should be increased

i can resize its height but i can't able to resize the width of verticalheader cell

plz do help me as soon as possible
thanks in advance

wysota
27th December 2006, 12:57
but my problem is i want to increase the size of icon or image which is placed in all verticalheader cells
Please describe your problem. In each post you seem to describe a different problem - first you wanted to insert an image into the header, then you wanted to change the size of the header and now you want to change the size of the image? Make up your mind...


i want like(see attachment) this
I won't see anything in the attachment as you are using a resource file that you don't attach to the ui, so I don't see any images.


but in this form the icon is very small i want that icon should be as large as cell height is...and cell width(where icon is placed) should be increased
Use QPixmap instead of QIcon then.


plz do help me as soon as possible

Please stop saying that, it really bugs people to read "please help me as soon as possible" or "this is urgent" - we always reply as soon as possible and everything is urgent for everyone.

jyoti
27th December 2006, 13:12
this is not my problem this is ur problem that u were nt getting me...
frm starting i had mentioned tht i want to increase the cell width and icon
after the i got some changes that icon should have same size as cell height is...problem can be changed with in two days
and this is my second day on the same problem i am still doing Research
so i dont think so its my fault that in which way u r taking it...
and what ever i had attached tht ws simply for ur clearification where actully the image is ...whti have to do...


anyways if u have any example code for it then do tell me

wysota
27th December 2006, 13:53
this is not my problem this is ur problem that u were nt getting me...
Yes, this is your problem, because if I can't understand you, I won't be able to help you, so it is in your best interest to try to explain clearly what you desire.


frm starting i had mentioned tht i want to increase the cell width and icon
after the i got some changes that icon should have same size as cell height is...problem can be changed with in two days
Please at least use complete words - there are no "frm", "tht", "u", "r" and simmilar words in English language. If you can't spare an additional minute to write "from", "that", "you" and "are" so that your message is easier to read, how come you expect us to help you "as soon as possible"? Believe me, using simple words and complete sentences without words having multiple meanings helps a lot to achieve your goals faster... In Poland we have a saying that it pleases the devil if a man is in a hurry ("Gdy się człowiek śpieszy, to się diabeł cieszy") that means that when you're in a hurry, you can loose more time correcting your mistakes than you'd spend doing the task properly in the first place. So please don't blaim me for not understanding your message.


i am still doing Research
And what did you find during that research?


so i dont think so its my fault that in which way u r taking it...
Does this sentence have a meaning? Because I don't see it here...


and what ever i had attached tht ws simply for ur clearification where actully the image is ...whti have to do...
All I see here is a grid with two items and a warning message box about a missing resource file being used asking me if I want to correct the path to the file.


anyways if u have any example code for it then do tell me

Example code for what? Reimplementing the sectionSizeHint?


int MyHeaderView::sectionSizeHint ( int logicalIndex ) const {
QVariant val = model()->headerData(logicalIndex, orientation(), Qt::DecorationRole);
QPixmap px = qvariant_cast<QPixmap>(val);
if(!px.isNull())
return px.size();
return QHeaderView::sectionSizeHint(logicalIndex);
}

You might also try simply setting the sizeHintRole for a particular section of the header.

jyoti
28th December 2006, 06:51
first of all thanks for replying...
and sorry to say but this ws not helpful for me
see just relax and think i tell you the problem step by step

1--->i have one tablewidget
each table have vertival header and horizontal header
2--->in horizontal header (col 0) name is ImageType and in horizontal header (col 1) Extention
3--->Now verticalheaderitem(0) is one icon and row(0)col(0) i have "Nikon" (that is inserted by code) & checkbox and in row(0)col(1) its having "Png" (inserted by coding)


MyProblem is

i want to increase the height and width of verticalheaderitem(0) which is an icon and icon height should be as same as cell height is like my cell height is 30 icon height should be same 30 and width should be half of the width of cell width

and my form name is imageselect an my function name is tableitems()
and i have toolbutton(in another mainwindow form) "openimageselect" in my toolbar
as i click this button the imageselect (dialog form) opened


now do tell me what is not clear to you so that i can make clear to u


yes you r right if i m nt clear then how will u solve the problem

form attached(below)

wysota
28th December 2006, 12:01
Then you want to adjust the size of the image to the size of the cell, not the size of the cell to the size of the image, correct? If that's so, you have to reimplement QHeaderView::paintSection() and scale the image before painting it.

jyoti
28th December 2006, 13:30
yes i want my verticalHeaderItem(0) height should be exactly equal to height of cell
and width should be half of cell width...
i had checked ur's given link but i didnot get the exactly fit function

i m using in code


tableWidget->verticalHeaderItem(0)->setIcon(QIcon(":/images/nikon.png"));
tableWidget->verticalHeaderItem(0)->setSizeHint(QSize(90,tableWidget->verticalHeaderItem(0)->sizeHint().height()+40));

this increases only the width height of cell not of the item(that is icon)



can u plz tell me its code example

wysota
28th December 2006, 13:46
i had checked ur's given link but i didnot get the exactly fit function

Because you have to reimplement that function - you have to do the drawing yourself using QPainter. For sample code take a look at QPainter docs or examples that come with Qt.

jyoti
29th December 2006, 07:12
thanks 4 the suggesion
in example nothing is mentioned for verticalHeaderItem in tablewidget...specially for increase the height of icon in tablewidget
if u have simple example the plz do tell me..

wysota
29th December 2006, 12:15
Because nothing has to be mentioned about it.... You just need to paint a scaled pixmap on a painter!


QPixmap sc = original.scaled(width, height, Qt:SmoothTransformation);
painter->drawPixmap(0, 0, sc);

Take a look at my previous snippet to see how to actually get the pixmap in the first place.