Results 1 to 14 of 14

Thread: how i can add image in verticalHeaderview() of tableWidget

  1. #1
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question how i can add image in verticalHeaderview() of tableWidget

    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

    Qt Code:
    1. int row=0;
    2. int RowCount=0;
    3. row=tableWidget->rowCount();
    4. tableWidget->setRowCount(row+1);
    5. QTableWidgetItem *item=new QTableWidgetItem("Nikon");
    6. item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
    7. item->setCheckState(Qt::Unchecked);
    8. tableWidget->setItem(RowCount,0,item);
    9.  
    10. QTableWidgetItem *item1=new QTableWidgetItem("Png ");
    11. tableWidget->setItem(RowCount,1,item1);
    To copy to clipboard, switch view to plain text mode 

    plz do suggest me as soon as possible,its urgent
    Attached Files Attached Files
    Last edited by wysota; 26th December 2006 at 14:29. Reason: missing [code] tags
    thanks & regards
    --------------------
    jyoti

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    Qt Code:
    1. tableWidget->verticalHeaderItem(0)->setData(Qt::DecorationRole, QPixmap("..."));
    To copy to clipboard, switch view to plain text mode 

    Is that what you want?

  3. The following user says thank you to wysota for this useful post:

    jyoti (27th December 2006)

  4. #3
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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
    thanks & regards
    --------------------
    jyoti

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    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?

  6. The following user says thank you to wysota for this useful post:

    jyoti (27th December 2006)

  7. #5
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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
    Attached Files Attached Files
    thanks & regards
    --------------------
    jyoti

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    Quote Originally Posted by jyoti View Post
    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.

  9. #7
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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
    thanks & regards
    --------------------
    jyoti

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    Quote Originally Posted by jyoti View Post
    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?

    Qt Code:
    1. int MyHeaderView::sectionSizeHint ( int logicalIndex ) const {
    2. QVariant val = model()->headerData(logicalIndex, orientation(), Qt::DecorationRole);
    3. QPixmap px = qvariant_cast<QPixmap>(val);
    4. if(!px.isNull())
    5. return px.size();
    6. return QHeaderView::sectionSizeHint(logicalIndex);
    7. }
    To copy to clipboard, switch view to plain text mode 

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

  11. The following user says thank you to wysota for this useful post:

    jyoti (28th December 2006)

  12. #9
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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)
    Attached Files Attached Files
    thanks & regards
    --------------------
    jyoti

  13. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    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.

  14. #11
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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
    Last edited by jyoti; 28th December 2006 at 12:40.
    thanks & regards
    --------------------
    jyoti

  15. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    Quote Originally Posted by jyoti View Post
    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.

  16. The following user says thank you to wysota for this useful post:

    jyoti (29th December 2006)

  17. #13
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: how i can add image in verticalHeaderview() of tableWidget

    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..
    thanks & regards
    --------------------
    jyoti

  18. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can add image in verticalHeaderview() of tableWidget

    Because nothing has to be mentioned about it.... You just need to paint a scaled pixmap on a painter!

    Qt Code:
    1. QPixmap sc = original.scaled(width, height, Qt:SmoothTransformation);
    2. painter->drawPixmap(0, 0, sc);
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  2. "sensitising" an image
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2006, 07:21
  3. Fast image drawing/scaling in Qt 3.3
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 10:45
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.