View Full Version : Is it possible to create a combo with paper sizes?
aekilic
16th January 2010, 12:44
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.
wysota
16th January 2010, 13:07
This should work:
QMetaEnum paperSizes = QPrinter::staticMetaObject().enumerator(QPrinter:: staticMetaObject().indexOfEnumerator("PaperSize"));
QStringList list;
QList<int> valueList;
for(int i=0;i<paperSizes.keyCount();i++){
list << key(i);
valueList << value(i);
}
QComboBox *box = new QComboBox;
for(int i=0;i<list.count();++i){
box->addItem(list.at(i), valueList.at(i));
}
aekilic
16th January 2010, 13:38
I have a error like
staticMetaObject is not a member of qprinter
wysota
16th January 2010, 14:07
Ouch... QPrinter is not a QObject... Well... this won't work then :)
aekilic
16th January 2010, 14:36
can we use
supportedPaperSources ?
wysota
16th January 2010, 14:58
Have a look at QPrintDialog sources.
Edit: Sorry, QPageSetupDialog...
aekilic
18th January 2010, 08:37
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
QPrinterInfo pinfo;
QList<QPrinter::PaperSize> paperSizes = pinfo.defaultPrinter().supportedPaperSizes();
QPrinter pppp;
QSizeF sizef;
QVariant height_variant;
QVariant width_variant;
int height;
int width;
for(int i=0;i<paperSizes.count();++i){
pppp.setPaperSize(paperSizes.at(i));
height = pppp. paperSize(QPrinter::Millimeter).height();
width = pppp. paperSize(QPrinter::Millimeter).width();
height_variant = height;
width_variant = width;
comboBox->addItem(height_variant.toString() + "x" + width_variant.toString());
}
nikhilqt
18th January 2010, 12:52
This link might help you.
http://www.gamedev.net/community/forums/topic.asp?topic_id=437852
wysota
18th January 2010, 16:24
This link might help you.
http://www.gamedev.net/community/forums/topic.asp?topic_id=437852
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.
nikhilqt
19th January 2010, 06:58
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 ?
wysota
19th January 2010, 10:16
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.