python - How to detect if a printer is conected with pyqt? -


i'm programming in linux windows application. in moment need solution detect if default printer connected. have next code:

def mprint(self, value):     font = qfont()     font.setpointsize(10)      self.meditor = qtextedit()     self.meditor.setfont(font)      self.printer = qprinter(qprinterinfo.defaultprinter())     self.printer.setcolormode(qprinter.grayscale)     self.printer.setpagemargins(7, 20, 7, 7, qprinter.millimeter)     self.printer.setorientation(qprinter.portrait)      try:         if value == 1:             self.printcommand()         else:             self.printdelivery()     except self.printer.error e:         print(e) 

with qprinterinfo can default printer , know if exists.

qprinterinfo.defaultprinter().isnull() 

but returns true, because have default printer in pc if not connected, goes printer queue.

does knows how recognize if printer connected , how show qmessage if there exception?

i find solution:

 self.meditor = qtextedit()  self.meditor.setfont(font)   self.printer = qprinter(qprinterinfo.defaultprinter())  self.meditor.document().print_(self.printer) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -