Results 1 to 5 of 5

Thread: QPixmap xx.scaledToWidth dont Scale but load...

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QPixmap xx.scaledToWidth dont Scale but load...

    I wand to scale an image on my CMS is this to much work if scale slot is a qslider

    or is int width QSize and not pixel?

    scaledToWidth ( int width, Qt::TransformationMode mode = Qt::FastTransformation ) const

    Qt Code:
    1. /* header */
    2. private:
    3. Gui_Image( QWidget* = 0 );
    4. QImage image;
    5. QPixmap myPixmap;
    6. QSize actual;
    7. /* header ..... */
    8.  
    9. /* i load image */
    10.  
    11. fileName = OpenFile("Image (*.png)");
    12.  
    13. if (!fileName.isEmpty()) {
    14. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(ModpicsChanged(int)));
    15. ...
    16. centrale->setPixmap(QPixmap::fromImage(image));
    17. ...
    18. centrale->adjustSize();
    19.  
    20. actual = centrale->pixmap()->size();
    21. ...
    22. horizontalSlider->setSliderPosition(wi);
    23. ...
    24. }
    25. /* ..... */
    26.  
    27. void Gui_Image::ModpicsChanged(int newvalue_w) /* int from QSlider 20px steeps */
    28. {
    29. ...
    30. myPixmap = QPixmap::fromImage(image);
    31. myPixmap.scaledToWidth(newvalue_w,Qt::FastTransformation);
    32. centrale->setPixmap(myPixmap); /* label */
    33. centrale->adjustSize(); /* label */
    34. actual = centrale->pixmap()->size();
    35. ...
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 25th June 2006 at 23:29. Reason: removed unrelevant code and fixed indentation

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap xx.scaledToWidth dont Scale but load...

    1. Why do you use both QImage and QPixmap?
      Conversion between QImage and QPixmap costs, especially on X Windows, so better use only QPixmaps (unless you have to access individual pixels).
    2. Have you read QPixmap::scaledToWidth() docs?
      If yes, do it again, but this time very carefully. Pay attention especially to the "const" keyword at the end of signature and the return type.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap xx.scaledToWidth dont Scale but load...

    Quote Originally Posted by jacek
    1. Why do you use both QImage and QPixmap?
      Conversion between QImage and QPixmap costs, especially on X Windows, so better use only QPixmaps (unless you have to access individual pixels).
    2. Have you read QPixmap::scaledToWidth() docs?
      If yes, do it again, but this time very carefully. Pay attention especially to the "const" keyword at the end of signature and the return type.
    if const at end i make a copy is right? ... now run ... ist very fast on transform...
    now qt4 taken moore points .... as Imagemagic on server..

    But now to save i must go toImage () const : QImage ... QPixmap dont save ... not found

    Qt Code:
    1. bool save ( const QString & fileName, const char * format, int quality = -1 ) const
    To copy to clipboard, switch view to plain text mode 

    /* running so ..*/
    Qt Code:
    1. void Gui_Image::ModpicsChanged(int newvalue_w) /* int from QSlider 20px steeps */
    2. {
    3. qDebug() << "### copyofimagefile... " << copyofimagefile;
    4. QPixmap pic(copyofimagefile);
    5. QPixmap scaled = pic.scaledToWidth(newvalue_w);
    6. centrale->setPixmap(scaled); /* label */
    7. centrale->adjustSize(); /* label */
    8. actual = centrale->pixmap()->size();
    9. qDebug() << "### Draw image and dispay new W x H px... ";
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap xx.scaledToWidth dont Scale but load...

    Quote Originally Posted by patrik08
    if const at end i make a copy is right?
    Not quite, const means that this method can't change the object.

    http://www.parashift.com/c++-faq-lit...rrectness.html

    Quote Originally Posted by patrik08
    But now to save i must go toImage ()
    No, you don't: QPixmap::save()

  5. The following user says thank you to jacek for this useful post:

    patrik08 (26th June 2006)

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap xx.scaledToWidth dont Scale but load...

    Quote Originally Posted by jacek
    Not quite, const means that this method can't change the object.
    I see is the same as a define on php but on objekt...

    Quote Originally Posted by jacek
    No, you don't: QPixmap::save()
    Ok and quality is same as gimp 70-80...

    Much tanks....

Similar Threads

  1. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 17:24

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.