Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. printing issue in a qt app pyqt5
QtWS25 Last Chance

printing issue in a qt app pyqt5

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 280 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    otaolafr
    wrote on last edited by
    #1

    Hello,
    I am using the software Salome-platform which is a pyQT application. In Salome, there is an embedded python console, and when the program is open at the same time it opens a terminal window (not the python one i mentioned previously but the classic terminal). In the python embedded console one can run python scripts, and if the python script has print on it it will print the output in the python console which is the desired behavior. but In some cases, when I create an Qtdialog which runs a function when the dialog is accepted and in this function it has a print function inside of it, the print ouput instead of print in the python console it will print in the terminal windows that opened at the same time as salome window.
    this is how it looks a small script where this behavior is happening (that the print output goes to the terminal windows instead of the python terminal inside the salome window as it classically does)

    from PyQt5.QtWidgets import QWidget, QMessageBox
    from PyQt5 import QtCore, QtGui
    import PyQt5.QtCore as QtCore
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import Qt
    
    def testForPrint(a):
      print(a) # -> if testForPrint is run from okbox.connect this will print in the terminal windows instead if instead the function is called from the main body it will print in the python console
      print(a,flush=True) # -> this will print in the terminal windows instead
      return
    
    bal='the dialog was accepted'
    print(bal) #-> this will print correctly into the python console
    
    dialog = QDialog()
    okbox = QDialogButtonBox(dialog)
    okbox.setOrientation(QtCore.Qt.Horizontal)
    okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
    okbox.setStyleSheet('QPushButton {font-weight: bold}')
    
    okbox.accepted.connect(lambda: testForPrint(bal))
    okbox.accepted.connect(lambda: dialog.hide())
    okbox.rejected.connect(lambda: dialog.hide())
    
    dialog.show()
    dialog.raise_()
    

    the structure of the script I need to keep it like this, as it is more complex and i need to wait until the testForPrint function is run to have the necessary data to print it. but would like that the print inside the function would be outputed to the python console instead of the terminal window. I know that this is pyqt related, as when I call the same function without calling it from the okbox button it will print correctly. would love some recommendations on how to solve this issue.

    jsulmJ 1 Reply Last reply
    0
    • O otaolafr

      Hello,
      I am using the software Salome-platform which is a pyQT application. In Salome, there is an embedded python console, and when the program is open at the same time it opens a terminal window (not the python one i mentioned previously but the classic terminal). In the python embedded console one can run python scripts, and if the python script has print on it it will print the output in the python console which is the desired behavior. but In some cases, when I create an Qtdialog which runs a function when the dialog is accepted and in this function it has a print function inside of it, the print ouput instead of print in the python console it will print in the terminal windows that opened at the same time as salome window.
      this is how it looks a small script where this behavior is happening (that the print output goes to the terminal windows instead of the python terminal inside the salome window as it classically does)

      from PyQt5.QtWidgets import QWidget, QMessageBox
      from PyQt5 import QtCore, QtGui
      import PyQt5.QtCore as QtCore
      from PyQt5.QtWidgets import *
      from PyQt5.QtCore import Qt
      
      def testForPrint(a):
        print(a) # -> if testForPrint is run from okbox.connect this will print in the terminal windows instead if instead the function is called from the main body it will print in the python console
        print(a,flush=True) # -> this will print in the terminal windows instead
        return
      
      bal='the dialog was accepted'
      print(bal) #-> this will print correctly into the python console
      
      dialog = QDialog()
      okbox = QDialogButtonBox(dialog)
      okbox.setOrientation(QtCore.Qt.Horizontal)
      okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
      okbox.setStyleSheet('QPushButton {font-weight: bold}')
      
      okbox.accepted.connect(lambda: testForPrint(bal))
      okbox.accepted.connect(lambda: dialog.hide())
      okbox.rejected.connect(lambda: dialog.hide())
      
      dialog.show()
      dialog.raise_()
      

      the structure of the script I need to keep it like this, as it is more complex and i need to wait until the testForPrint function is run to have the necessary data to print it. but would like that the print inside the function would be outputed to the python console instead of the terminal window. I know that this is pyqt related, as when I call the same function without calling it from the okbox button it will print correctly. would love some recommendations on how to solve this issue.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @otaolafr said in printing issue in a qt app pyqt5:

      I am using the software Salome-platform

      Shouldn't you ask them? I doubt anybody here knows the internals of that software.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply
      1
      • jsulmJ jsulm

        @otaolafr said in printing issue in a qt app pyqt5:

        I am using the software Salome-platform

        Shouldn't you ask them? I doubt anybody here knows the internals of that software.

        O Offline
        O Offline
        otaolafr
        wrote on last edited by
        #3

        @jsulm Hello!
        Yes I asked in their forum, but sadly there is not a lot of users that are active in the forum. and this issue only rises when I use pyqt5 (not saying that there is something wrong with it, but simply that i am doing something wrong myself XD) i thougt that maybe with a little bit of luck someone had had the same kind of issue in another application...
        regards

        SGaistS 1 Reply Last reply
        0
        • O otaolafr

          @jsulm Hello!
          Yes I asked in their forum, but sadly there is not a lot of users that are active in the forum. and this issue only rises when I use pyqt5 (not saying that there is something wrong with it, but simply that i am doing something wrong myself XD) i thougt that maybe with a little bit of luck someone had had the same kind of issue in another application...
          regards

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @otaolafr hi,

          Do you have the same issue if your use PySide6 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          O 1 Reply Last reply
          0
          • SGaistS SGaist

            @otaolafr hi,

            Do you have the same issue if your use PySide6 ?

            O Offline
            O Offline
            otaolafr
            wrote on last edited by
            #5

            @SGaist Hello!
            thanks for your answer,
            sadly, PySide6 is not available inside salome, and I am afraid that if i install it inside the embebed python it might break the application itself (as it is a pyqt5 app)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              AFAIK, both packages can coexist in the same environment as they come each with their own build of Qt.
              However, to get better help, as @jsulm suggested, you should bring that issue to the Salome forum.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved