Results 1 to 20 of 20

Thread: vector image

  1. #1
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default vector image

    Hi how can I insert into my graphics scene vector image? QT supports only svg files? or some other files (eps, ps...) too? If yes, so what?

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

    Default Re: vector image

    Unless you provide an image plugin for reading such files, you'll have to convert them to some supported format.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    Quote Originally Posted by wysota View Post
    Unless you provide an image plugin for reading such files, you'll have to convert them to some supported format.
    could you give me some hint, how to convert to supported format? thanks

    i tried this
    Qt Code:
    1. void MainWindow::loadVectorImage()
    2. {
    3. const QString fileName = QFileDialog::getOpenFileName(this, tr("Select Vector Images"),
    4. QDesktopServices::storageLocation(QDesktopServices::PicturesLocation),
    5. "*.pdf *eps *.ps *.svg");
    6.  
    7. QPicture picture;
    8. if (fileName.isEmpty() || !picture.load(fileName)) return;// loading to image
    9.  
    10. QPixmap imageNew;
    11. QPainter painter;
    12. painter.begin(&imageNew); // paint in imageNew
    13. painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
    14. painter.end();
    15.  
    16.  
    17. // set vector image to scene image into scene
    18. scene->openImage(imageNew);
    19. }
    To copy to clipboard, switch view to plain text mode 
    but it doesnt work

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

    Default Re: vector image

    You have to use some application that is able to read your format and write one of supported formats. To see what formats are supported by your installation of Qt, use QImageReader::supportedImageFormats().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    so I should use svg? Because QImageReader::supportedImageFormats() are bitmap file, arent they?

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

    Default Re: vector image

    At some point you will have to convert your vector image to bitmap anyway, so it's your choice when to do it. If you want to go for svg, that's fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    thanks but I dont know how I should to convert vector image to pixmap...
    when I tried this code (I wrote it in this thread) it doesnot work.
    Then I found thisand Alex answer is similar with my code
    load vector image into QPicture
    Qt Code:
    1. QPicture picture;
    2. picture.load(fileName))
    3. QPixmap imageNew(100, 100);
    4. imageNew.fill();
    5. QPainter painter(&imageNew); // ??? convert to pixmap ???
    6. painter.drawPicture(0, 0, picture);// paint to paniter
    To copy to clipboard, switch view to plain text mode 
    but nothing happens

    edit: so problem could be in "picture.load(fileName)" but I dont know why, I though that QPicture::load it should be ok but it isnot
    Last edited by Noxxik; 10th March 2009 at 23:00.

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

    Default Re: vector image

    I don't see a point of loading the image to the picture and them immediately trying to put it on a pixmap. You could load it to the pixmap directly. By the way, if you have an svg image, you have to use QSvgRenderer to transfer it to a pixmap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    sorry for my stupid answers, could you help me once again how I should to load a vector image? I thought that I tried to load vector image in QPicture to the pixmap directly.
    svg images dont have to be default, rather I would like to load image in pdf or in eps file

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

    Default Re: vector image

    I already told you you can't load a postscript image to Qt applications directly, because neither of these formats are supported. You have to convert your vector image to some other supported format using a 3rd party application such as Gimp or ImageMagick and then load it into Qt. You can also use a 3rd party library (such as poppler for PDF) to do that inside your application. In the end you will have to have a raster representation of the image, regardless if you use PDF, EPS, SVG or PNG. The only thing you can decide is when to do the conversion and what resolution to use in case of vector graphics.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    Quote Originally Posted by wysota View Post
    I already told you you can't load a postscript image to Qt applications directly, because neither of these formats are supported. You have to convert your vector image to some other supported format using a 3rd party application such as Gimp or ImageMagick and then load it into Qt. You can also use a 3rd party library (such as poppler for PDF) to do that inside your application. In the end you will have to have a raster representation of the image, regardless if you use PDF, EPS, SVG or PNG. The only thing you can decide is when to do the conversion and what resolution to use in case of vector graphics.
    thanks I am trying poppler library, but it writes me one error, when I try to compile my programme
    my compilor mingw wrote this error
    undefined reference to '_imp___ZN7Poppler8Document4loadERK7QStringRK10QBy teArrayS6_'

    but I dont know where I have mistake

    I wrote this...
    Qt Code:
    1. const QString fileName = QFileDialog::getOpenFileName(this, languages[1],
    2. QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation),
    3. "*.pdf");
    4.  
    5. Poppler::Document *document = Poppler::Document::load(fileName); // this is the error
    6. if (!document/* || document->isLocked()*/) {
    7.  
    8. QMessageBox::information(this, tr("Business Card Generator"), tr("Cannot load %1.").arg(fileName));
    9.  
    10. // delete document;
    11. return;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Do you know where I have mistake please? or what could I have do? please

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

    Default Re: vector image

    Did you link against the library?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    Quote Originally Posted by wysota View Post
    Did you link against the library?
    I think yes... I have at top of file.cpp this...
    #include <src/poppler-qt4.h>

    in src folder I have all which is in "poppler-0.10.4\qt4\src"

    edit: or I should add reference src/poppler-qt4.h to myprogram.pro ?

    edit2: or I should add some folder to "Qt\4.4.1\src\3rdparty" or some oter place?
    Last edited by Noxxik; 11th March 2009 at 15:53.

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

    Default Re: vector image

    Quote Originally Posted by Noxxik View Post
    #include <src/poppler-qt4.h>
    This only includes the header file into the compilation unit.

    edit: or I should add reference src/poppler-qt4.h to myprogram.pro ?

    edit2: or I should add some folder to "Qt\4.4.1\src\3rdparty" or some oter place?
    You should add an entry similar to:
    qmake Code:
    1. LIBS+=-lpoppler
    To copy to clipboard, switch view to plain text mode 
    to your project file and rerun qmake.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    So I tried it how you wrote me...
    So in programm.pro I have
    Qt Code:
    1. TEMPLATE = app
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5. LIBS += -lpoppler
    6. # Input
    7. HEADERS += mainscene.h \
    8. # other *.h file
    9. SOURCES += main.cpp \
    10. # other *.cpp file
    11. RESOURCES += images.qrc
    12. RC_FILE = icon.rc
    To copy to clipboard, switch view to plain text mode 
    but mingw wrote me, that it dont find -lpoppler it wrote this:
    C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\ mingw32\bin\ld.exe: cannot find -lpoppler
    I dont know where I add some this files

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

    Default Re: vector image

    I didn't say you had to copy exactly what I wrote. Please open QMake docs and see what the LIBS variable does and what to put in it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    so I read thisbut I dont understand very well how to add poppler file to my project
    if I would add something like this win32:LIBS += c:/mylibs/math.lib in poppler-0.10.4 I didnt find any lib files or I have to install poppler? I dont know how it install in windows

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

    Default Re: vector image

    Yes, you have to install poppler. You can't use something you don't have.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Noxxik (13th March 2009)

  20. #19
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    So I should find some manual how to install in windows, but I cannot find any manual. I tried find something, but instalation in windows it is not so easy

  21. #20
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    I remove poppler library and I add only svg images. So thank you for help
    I send you thanks

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.