完全なテーブルビューを PyQt アプリから pdf にエクスポートしようとして、大きな障害にぶつかっています。
私はある種のPDFエクスポートを行うことができましたが、それらは常に現在の表示領域によってトリミングされて出てきます。
エクスポート時に一部しか表示されていない場合でも、完全なテーブルビューをエクスポートする例を探しています。
このテーブルビューにはサムネイルがいくつかあるので、目に見える画像をキャプチャするものになると思います。
これは私が持っているコードで、テーブルビューの一部でpdfをエクスポートすることができます。ヒントをいただければ幸いです。
def _print(self, checked = None):
if checked == None: return
fileName = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '', 'PDF Files (*.pdf)')
if fileName == '': return
#set up the QPrinter
p = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
p.setPaperSize(QtGui.QPrinter.A4)
p.setOutputFormat(QtGui.QPrinter.PdfFormat)
p.setOrientation(QtGui.QPrinter.Landscape)
p.setOutputFileName(fileName)
#set up the painter
painter = QtGui.QPainter()
#Activate the painter to paint on p then give visual conformation that it worked or not.
#If didn't work return out of method.
if painter.begin(p) == False:
msgBox = QtGui.QMessageBox()
msgBox.setText('An Error occoured while creating PDF')
msgBox.setInformativeText('Could not save PDF')
msgBox.setIcon(QtGui.QMessageBox.Critical)
msgBox.exec_()
return
#self.ShotTableView.scale(200, 200);
#painter.begin(printer)
print self.ShotTableView.width()
xscale = (self.ShotTableView.width() / 50);
yscale = (self.ShotTableView.height() / 50);
#scale = qMin(xscale, yscale);
painter.scale(xscale, yscale);
self.ShotTableView.render(painter)
painter.end()