Problem : PyQt5 QMessageBox on the foreground










0















I have a problem when i'm trying to pop up a QMessageBox, with Pyqt5 Python 3.5
It is in the background not foreground.
I have tried different read on this forum, without success.
This QMessage is called when I click on the Save Button



My all code:



import os
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog,QMessageBox
import pyqtgraph as pg
import pyqtgraph.exporters


class Ui_Viewer(QtWidgets.QMainWindow):

def __init__(self, parent=None):
self.parent = parent
super(Ui_Viewer, self).__init__()
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)

def createWindow(self):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowTitle("My Viewer")
self.resize(1280, 960)
self.Button_Save = QtWidgets.QPushButton(self.central_widget)
self.Button_Save.setGeometry(10, 10, 70, 30)
self.Button_Save.setStyleSheet("background-color: rgb(109, 109, 109);")
self.Button_Save.setText("Save")
self.Button_Save.clicked.connect(self.process_Save_Figure)

def process_Save_Figure(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint)
msgBox.warning(msgBox.setStyleSheet("background-color:gray;"), 'Information',
"Save Data")

def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_Viewer()
MainWindow.createWindow()
MainWindow.show()

rc = app.exec_()
sys.exit(rc)


if __name__ == "__main__":
main()









share|improve this question






















  • If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

    – ekhumoro
    Nov 13 '18 at 13:19
















0















I have a problem when i'm trying to pop up a QMessageBox, with Pyqt5 Python 3.5
It is in the background not foreground.
I have tried different read on this forum, without success.
This QMessage is called when I click on the Save Button



My all code:



import os
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog,QMessageBox
import pyqtgraph as pg
import pyqtgraph.exporters


class Ui_Viewer(QtWidgets.QMainWindow):

def __init__(self, parent=None):
self.parent = parent
super(Ui_Viewer, self).__init__()
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)

def createWindow(self):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowTitle("My Viewer")
self.resize(1280, 960)
self.Button_Save = QtWidgets.QPushButton(self.central_widget)
self.Button_Save.setGeometry(10, 10, 70, 30)
self.Button_Save.setStyleSheet("background-color: rgb(109, 109, 109);")
self.Button_Save.setText("Save")
self.Button_Save.clicked.connect(self.process_Save_Figure)

def process_Save_Figure(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint)
msgBox.warning(msgBox.setStyleSheet("background-color:gray;"), 'Information',
"Save Data")

def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_Viewer()
MainWindow.createWindow()
MainWindow.show()

rc = app.exec_()
sys.exit(rc)


if __name__ == "__main__":
main()









share|improve this question






















  • If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

    – ekhumoro
    Nov 13 '18 at 13:19














0












0








0








I have a problem when i'm trying to pop up a QMessageBox, with Pyqt5 Python 3.5
It is in the background not foreground.
I have tried different read on this forum, without success.
This QMessage is called when I click on the Save Button



My all code:



import os
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog,QMessageBox
import pyqtgraph as pg
import pyqtgraph.exporters


class Ui_Viewer(QtWidgets.QMainWindow):

def __init__(self, parent=None):
self.parent = parent
super(Ui_Viewer, self).__init__()
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)

def createWindow(self):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowTitle("My Viewer")
self.resize(1280, 960)
self.Button_Save = QtWidgets.QPushButton(self.central_widget)
self.Button_Save.setGeometry(10, 10, 70, 30)
self.Button_Save.setStyleSheet("background-color: rgb(109, 109, 109);")
self.Button_Save.setText("Save")
self.Button_Save.clicked.connect(self.process_Save_Figure)

def process_Save_Figure(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint)
msgBox.warning(msgBox.setStyleSheet("background-color:gray;"), 'Information',
"Save Data")

def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_Viewer()
MainWindow.createWindow()
MainWindow.show()

rc = app.exec_()
sys.exit(rc)


if __name__ == "__main__":
main()









share|improve this question














I have a problem when i'm trying to pop up a QMessageBox, with Pyqt5 Python 3.5
It is in the background not foreground.
I have tried different read on this forum, without success.
This QMessage is called when I click on the Save Button



My all code:



import os
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog,QMessageBox
import pyqtgraph as pg
import pyqtgraph.exporters


class Ui_Viewer(QtWidgets.QMainWindow):

def __init__(self, parent=None):
self.parent = parent
super(Ui_Viewer, self).__init__()
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)

def createWindow(self):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowTitle("My Viewer")
self.resize(1280, 960)
self.Button_Save = QtWidgets.QPushButton(self.central_widget)
self.Button_Save.setGeometry(10, 10, 70, 30)
self.Button_Save.setStyleSheet("background-color: rgb(109, 109, 109);")
self.Button_Save.setText("Save")
self.Button_Save.clicked.connect(self.process_Save_Figure)

def process_Save_Figure(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint)
msgBox.warning(msgBox.setStyleSheet("background-color:gray;"), 'Information',
"Save Data")

def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_Viewer()
MainWindow.createWindow()
MainWindow.show()

rc = app.exec_()
sys.exit(rc)


if __name__ == "__main__":
main()






python pyqt5






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 12:27









Jérôme PannetierJérôme Pannetier

354




354












  • If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

    – ekhumoro
    Nov 13 '18 at 13:19


















  • If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

    – ekhumoro
    Nov 13 '18 at 13:19

















If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

– ekhumoro
Nov 13 '18 at 13:19






If you want to customise a message-box, don't use the static methods like warning(), because they will create an separate, internal instance of QMessageBox which you cannot access. You need to use the propery-based API to explicitly set all the options, and then show the dialog with exec().

– ekhumoro
Nov 13 '18 at 13:19













2 Answers
2






active

oldest

votes


















0














try this code:



 def process_Save_Figure(self):
msgBox = QMessageBox()
msgBox.warning(self, 'Information',"Save Data")


if it's works you can apply your style.






share|improve this answer























  • Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

    – Jérôme Pannetier
    Nov 13 '18 at 12:59











  • so it's solved?

    – Tsifi Stifen
    Nov 13 '18 at 14:25


















0














The problem disappears when I comment out the line self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



(tested on PySide2)






share|improve this answer























  • Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

    – Jérôme Pannetier
    Nov 13 '18 at 12:43










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281007%2fproblem-pyqt5-qmessagebox-on-the-foreground%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














try this code:



 def process_Save_Figure(self):
msgBox = QMessageBox()
msgBox.warning(self, 'Information',"Save Data")


if it's works you can apply your style.






share|improve this answer























  • Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

    – Jérôme Pannetier
    Nov 13 '18 at 12:59











  • so it's solved?

    – Tsifi Stifen
    Nov 13 '18 at 14:25















0














try this code:



 def process_Save_Figure(self):
msgBox = QMessageBox()
msgBox.warning(self, 'Information',"Save Data")


if it's works you can apply your style.






share|improve this answer























  • Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

    – Jérôme Pannetier
    Nov 13 '18 at 12:59











  • so it's solved?

    – Tsifi Stifen
    Nov 13 '18 at 14:25













0












0








0







try this code:



 def process_Save_Figure(self):
msgBox = QMessageBox()
msgBox.warning(self, 'Information',"Save Data")


if it's works you can apply your style.






share|improve this answer













try this code:



 def process_Save_Figure(self):
msgBox = QMessageBox()
msgBox.warning(self, 'Information',"Save Data")


if it's works you can apply your style.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 12:40









Tsifi StifenTsifi Stifen

163




163












  • Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

    – Jérôme Pannetier
    Nov 13 '18 at 12:59











  • so it's solved?

    – Tsifi Stifen
    Nov 13 '18 at 14:25

















  • Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

    – Jérôme Pannetier
    Nov 13 '18 at 12:59











  • so it's solved?

    – Tsifi Stifen
    Nov 13 '18 at 14:25
















Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

– Jérôme Pannetier
Nov 13 '18 at 12:59





Hello Tsifi , Your method's work correctly. Of course. Nevertheless, I can change my style of my messagebox. It inherits of style of my parent...

– Jérôme Pannetier
Nov 13 '18 at 12:59













so it's solved?

– Tsifi Stifen
Nov 13 '18 at 14:25





so it's solved?

– Tsifi Stifen
Nov 13 '18 at 14:25













0














The problem disappears when I comment out the line self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



(tested on PySide2)






share|improve this answer























  • Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

    – Jérôme Pannetier
    Nov 13 '18 at 12:43















0














The problem disappears when I comment out the line self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



(tested on PySide2)






share|improve this answer























  • Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

    – Jérôme Pannetier
    Nov 13 '18 at 12:43













0












0








0







The problem disappears when I comment out the line self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



(tested on PySide2)






share|improve this answer













The problem disappears when I comment out the line self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



(tested on PySide2)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 12:36









myrmicamyrmica

39618




39618












  • Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

    – Jérôme Pannetier
    Nov 13 '18 at 12:43

















  • Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

    – Jérôme Pannetier
    Nov 13 '18 at 12:43
















Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

– Jérôme Pannetier
Nov 13 '18 at 12:43





Hy 7t7 Studios , Thank you. Nevertheless, if i apply your method, my first windows is killed :(

– Jérôme Pannetier
Nov 13 '18 at 12:43

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281007%2fproblem-pyqt5-qmessagebox-on-the-foreground%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党