Results 1 to 11 of 11

Thread: Is it possible to create a combo with paper sizes?

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Is it possible to create a combo with paper sizes?

    Dear all

    I am trying to do create a combo with paper sizes on the system.

    I try to do it with
    QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes () const;

    But I want able to get the list yes.

  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: Is it possible to create a combo with paper sizes?

    This should work:
    Qt Code:
    1. QMetaEnum paperSizes = QPrinter::staticMetaObject().enumerator(QPrinter::staticMetaObject().indexOfEnumerator("PaperSize"));
    2. QList<int> valueList;
    3. for(int i=0;i<paperSizes.keyCount();i++){
    4. list << key(i);
    5. valueList << value(i);
    6. }
    7. QComboBox *box = new QComboBox;
    8. for(int i=0;i<list.count();++i){
    9. box->addItem(list.at(i), valueList.at(i));
    10. }
    To copy to clipboard, switch view to plain text mode 
    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
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a combo with paper sizes?

    I have a error like

    staticMetaObject is not a member of qprinter

  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: Is it possible to create a combo with paper sizes?

    Ouch... QPrinter is not a QObject... Well... this won't work then
    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
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a combo with paper sizes?

    can we use

    supportedPaperSources ?

  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: Is it possible to create a combo with paper sizes?

    Have a look at QPrintDialog sources.

    Edit: Sorry, QPageSetupDialog...
    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
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a combo with paper sizes?

    I was able to get the dimentions of the pages right now, but I still cant get the names, maybe this would be helpfull for someone

    Qt Code:
    1. QPrinterInfo pinfo;
    2. QList<QPrinter::PaperSize> paperSizes = pinfo.defaultPrinter().supportedPaperSizes();
    3. QPrinter pppp;
    4. QSizeF sizef;
    5. QVariant height_variant;
    6. QVariant width_variant;
    7. int height;
    8. int width;
    9.  
    10. for(int i=0;i<paperSizes.count();++i){
    11. pppp.setPaperSize(paperSizes.at(i));
    12.  
    13. height = pppp. paperSize(QPrinter::Millimeter).height();
    14. width = pppp. paperSize(QPrinter::Millimeter).width();
    15.  
    16. height_variant = height;
    17. width_variant = width;
    18. comboBox->addItem(height_variant.toString() + "x" + width_variant.toString());
    19. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Is it possible to create a combo with paper sizes?


  9. #9
    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: Is it possible to create a combo with paper sizes?

    Quote Originally Posted by nikhilqt View Post
    That's not really an answer. Qt can do such things on its own but it requires the enum to be defined in a QObject which is not the case here. I suspect it would be possible to declare a dummy QObject and declare the paper size enum there but it doesn't seem like a good solution.
    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.


  10. #10
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Is it possible to create a combo with paper sizes?

    Quote Originally Posted by wysota View Post
    That's not really an answer. Qt can do such things on its own but it requires the enum to be defined in a QObject which is not the case here. I suspect it would be possible to declare a dummy QObject and declare the paper size enum there but it doesn't seem like a good solution.
    Ok. Then the routine you written above in this thread would work, right ? Since QPrinter is not derived from QObject, I suggested the link regarding C++. Is there any reason why QPrinter is not a part of QObject ?

  11. #11
    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: Is it possible to create a combo with paper sizes?

    Quote Originally Posted by nikhilqt View Post
    Then the routine you written above in this thread would work, right ?
    Yes.

    Since QPrinter is not derived from QObject, I suggested the link regarding C++.
    Ok, but then you have to manually construct mapping from enum to strings so you can just insert those strings to the combo-box instead. The same amount of work. I think the solution the thread author is looking for is to do this automatically.

    Is there any reason why QPrinter is not a part of QObject ?
    There is no reason for it to be a QObject.
    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.


Similar Threads

  1. TSP problem paper
    By mickey in forum General Discussion
    Replies: 3
    Last Post: 5th May 2009, 16:50
  2. Replies: 0
    Last Post: 26th October 2008, 13:56
  3. How I setup QPrinter paper margins
    By vcp in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2008, 17:43
  4. DropDown combo box
    By Tavit in forum Qt Programming
    Replies: 3
    Last Post: 3rd May 2008, 08:40
  5. Printing and Paper Geometry
    By croftj in forum Qt Programming
    Replies: 5
    Last Post: 19th December 2007, 21:29

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.