How to keep QGIS plugins always on top of the main window?












1















When writing a simple QGIS 3 plugin via Plugin Builder 3, is there a simple way to tell QGIS not to hide the dialog box when the mouse clicks outside it?



I have tried a few options without luck,
How to show QGIS plugin dialog always on top?, https://stackoverflow.com/questions/1925015/pyqt-always-on-top



Or is there an option within QGIS to command plugin displays?



Editing for including my code:



def __init__(self, iface):

#always on top
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)

"""Constructor.

:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'UpdateAttribute_{}.qm'.format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)

# Declare instance attributes
self.actions =
self.menu = self.tr(u'&Update Attribute')

# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None


UPDATE



The two suggested lines just needed to be moved to the run(self) section. Replace 'UpdateAttributeDialog()' by the name of your dialog.



 def run(self):
"""Run method that performs all the real work"""

# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
#if self.first_start == True:
# self.first_start = False
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)









share|improve this question

























  • I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

    – Michael Stimson
    2 hours ago






  • 1





    Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

    – xunilk
    2 hours ago











  • @Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

    – xunilk
    2 hours ago













  • @xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

    – Leo
    2 hours ago











  • Good for you. Please, consider also mark the question as accepted. Thanks.

    – xunilk
    1 hour ago
















1















When writing a simple QGIS 3 plugin via Plugin Builder 3, is there a simple way to tell QGIS not to hide the dialog box when the mouse clicks outside it?



I have tried a few options without luck,
How to show QGIS plugin dialog always on top?, https://stackoverflow.com/questions/1925015/pyqt-always-on-top



Or is there an option within QGIS to command plugin displays?



Editing for including my code:



def __init__(self, iface):

#always on top
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)

"""Constructor.

:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'UpdateAttribute_{}.qm'.format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)

# Declare instance attributes
self.actions =
self.menu = self.tr(u'&Update Attribute')

# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None


UPDATE



The two suggested lines just needed to be moved to the run(self) section. Replace 'UpdateAttributeDialog()' by the name of your dialog.



 def run(self):
"""Run method that performs all the real work"""

# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
#if self.first_start == True:
# self.first_start = False
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)









share|improve this question

























  • I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

    – Michael Stimson
    2 hours ago






  • 1





    Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

    – xunilk
    2 hours ago











  • @Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

    – xunilk
    2 hours ago













  • @xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

    – Leo
    2 hours ago











  • Good for you. Please, consider also mark the question as accepted. Thanks.

    – xunilk
    1 hour ago














1












1








1


1






When writing a simple QGIS 3 plugin via Plugin Builder 3, is there a simple way to tell QGIS not to hide the dialog box when the mouse clicks outside it?



I have tried a few options without luck,
How to show QGIS plugin dialog always on top?, https://stackoverflow.com/questions/1925015/pyqt-always-on-top



Or is there an option within QGIS to command plugin displays?



Editing for including my code:



def __init__(self, iface):

#always on top
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)

"""Constructor.

:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'UpdateAttribute_{}.qm'.format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)

# Declare instance attributes
self.actions =
self.menu = self.tr(u'&Update Attribute')

# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None


UPDATE



The two suggested lines just needed to be moved to the run(self) section. Replace 'UpdateAttributeDialog()' by the name of your dialog.



 def run(self):
"""Run method that performs all the real work"""

# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
#if self.first_start == True:
# self.first_start = False
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)









share|improve this question
















When writing a simple QGIS 3 plugin via Plugin Builder 3, is there a simple way to tell QGIS not to hide the dialog box when the mouse clicks outside it?



I have tried a few options without luck,
How to show QGIS plugin dialog always on top?, https://stackoverflow.com/questions/1925015/pyqt-always-on-top



Or is there an option within QGIS to command plugin displays?



Editing for including my code:



def __init__(self, iface):

#always on top
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)

"""Constructor.

:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'UpdateAttribute_{}.qm'.format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)

# Declare instance attributes
self.actions =
self.menu = self.tr(u'&Update Attribute')

# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None


UPDATE



The two suggested lines just needed to be moved to the run(self) section. Replace 'UpdateAttributeDialog()' by the name of your dialog.



 def run(self):
"""Run method that performs all the real work"""

# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
#if self.first_start == True:
# self.first_start = False
self.dlg = UpdateAttributeDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)






pyqgis display plugins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago







Leo

















asked 4 hours ago









LeoLeo

1028




1028













  • I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

    – Michael Stimson
    2 hours ago






  • 1





    Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

    – xunilk
    2 hours ago











  • @Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

    – xunilk
    2 hours ago













  • @xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

    – Leo
    2 hours ago











  • Good for you. Please, consider also mark the question as accepted. Thanks.

    – xunilk
    1 hour ago



















  • I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

    – Michael Stimson
    2 hours ago






  • 1





    Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

    – xunilk
    2 hours ago











  • @Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

    – xunilk
    2 hours ago













  • @xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

    – Leo
    2 hours ago











  • Good for you. Please, consider also mark the question as accepted. Thanks.

    – xunilk
    1 hour ago

















I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

– Michael Stimson
2 hours ago





I'd rather see your code as text pasted and formatted than as a screen shot, it makes it easier to copy/paste to try out the code you've presented to replicate the problem you're experiencing.

– Michael Stimson
2 hours ago




1




1





Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

– xunilk
2 hours ago





Please erase your two added lines below #always on top. Find out this line 'Create the dialog (after translation) and keep reference'. Below self.dlg.AttributeDialog place self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint).

– xunilk
2 hours ago













@Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

– xunilk
2 hours ago







@Michael Stimson I had to see that image to find out the issue. Two lines were placed in a wrong way.

– xunilk
2 hours ago















@xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

– Leo
2 hours ago





@xunilk Hooray! It's working! Thank you so much for your help, you've been amazing!

– Leo
2 hours ago













Good for you. Please, consider also mark the question as accepted. Thanks.

– xunilk
1 hour ago





Good for you. Please, consider also mark the question as accepted. Thanks.

– xunilk
1 hour ago










1 Answer
1






active

oldest

votes


















2














Yes, there are a simple way. I found out one for QGIS 3 and, I think that is also equivalent for QGIS 2 because is based in 'setWindowFlags' method for QDialog (see this answer). For QGIS 3, it's necessary to import Qt module from PyQt5.QtCore and to include one instruction in init method; as is pointed out in snippet code below:



.
.
.
from PyQt5.QtCore import Qt
.
.
.
def __init__(self, iface):
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.


On the other hand, there is an option within QGIS to command plugin displays 'Always On Top'. With cursor on plugin window dialog (bottom bar), click on mouse right button and mark 'Always On Top' option in contextual menu; as it can be observed at below image.



enter image description here






share|improve this answer
























  • Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

    – Leo
    3 hours ago













  • Windows doesn't allow the 'Always on top feature'

    – Leo
    3 hours ago











  • It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

    – xunilk
    2 hours ago











  • By the way, what windows do you use?

    – xunilk
    2 hours ago











  • Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

    – Leo
    2 hours ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fgis.stackexchange.com%2fquestions%2f308494%2fhow-to-keep-qgis-plugins-always-on-top-of-the-main-window%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Yes, there are a simple way. I found out one for QGIS 3 and, I think that is also equivalent for QGIS 2 because is based in 'setWindowFlags' method for QDialog (see this answer). For QGIS 3, it's necessary to import Qt module from PyQt5.QtCore and to include one instruction in init method; as is pointed out in snippet code below:



.
.
.
from PyQt5.QtCore import Qt
.
.
.
def __init__(self, iface):
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.


On the other hand, there is an option within QGIS to command plugin displays 'Always On Top'. With cursor on plugin window dialog (bottom bar), click on mouse right button and mark 'Always On Top' option in contextual menu; as it can be observed at below image.



enter image description here






share|improve this answer
























  • Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

    – Leo
    3 hours ago













  • Windows doesn't allow the 'Always on top feature'

    – Leo
    3 hours ago











  • It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

    – xunilk
    2 hours ago











  • By the way, what windows do you use?

    – xunilk
    2 hours ago











  • Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

    – Leo
    2 hours ago


















2














Yes, there are a simple way. I found out one for QGIS 3 and, I think that is also equivalent for QGIS 2 because is based in 'setWindowFlags' method for QDialog (see this answer). For QGIS 3, it's necessary to import Qt module from PyQt5.QtCore and to include one instruction in init method; as is pointed out in snippet code below:



.
.
.
from PyQt5.QtCore import Qt
.
.
.
def __init__(self, iface):
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.


On the other hand, there is an option within QGIS to command plugin displays 'Always On Top'. With cursor on plugin window dialog (bottom bar), click on mouse right button and mark 'Always On Top' option in contextual menu; as it can be observed at below image.



enter image description here






share|improve this answer
























  • Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

    – Leo
    3 hours ago













  • Windows doesn't allow the 'Always on top feature'

    – Leo
    3 hours ago











  • It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

    – xunilk
    2 hours ago











  • By the way, what windows do you use?

    – xunilk
    2 hours ago











  • Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

    – Leo
    2 hours ago
















2












2








2







Yes, there are a simple way. I found out one for QGIS 3 and, I think that is also equivalent for QGIS 2 because is based in 'setWindowFlags' method for QDialog (see this answer). For QGIS 3, it's necessary to import Qt module from PyQt5.QtCore and to include one instruction in init method; as is pointed out in snippet code below:



.
.
.
from PyQt5.QtCore import Qt
.
.
.
def __init__(self, iface):
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.


On the other hand, there is an option within QGIS to command plugin displays 'Always On Top'. With cursor on plugin window dialog (bottom bar), click on mouse right button and mark 'Always On Top' option in contextual menu; as it can be observed at below image.



enter image description here






share|improve this answer













Yes, there are a simple way. I found out one for QGIS 3 and, I think that is also equivalent for QGIS 2 because is based in 'setWindowFlags' method for QDialog (see this answer). For QGIS 3, it's necessary to import Qt module from PyQt5.QtCore and to include one instruction in init method; as is pointed out in snippet code below:



.
.
.
from PyQt5.QtCore import Qt
.
.
.
def __init__(self, iface):
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.


On the other hand, there is an option within QGIS to command plugin displays 'Always On Top'. With cursor on plugin window dialog (bottom bar), click on mouse right button and mark 'Always On Top' option in contextual menu; as it can be observed at below image.



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









xunilkxunilk

14k31742




14k31742













  • Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

    – Leo
    3 hours ago













  • Windows doesn't allow the 'Always on top feature'

    – Leo
    3 hours ago











  • It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

    – xunilk
    2 hours ago











  • By the way, what windows do you use?

    – xunilk
    2 hours ago











  • Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

    – Leo
    2 hours ago





















  • Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

    – Leo
    3 hours ago













  • Windows doesn't allow the 'Always on top feature'

    – Leo
    3 hours ago











  • It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

    – xunilk
    2 hours ago











  • By the way, what windows do you use?

    – xunilk
    2 hours ago











  • Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

    – Leo
    2 hours ago



















Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

– Leo
3 hours ago







Thank you @xunilk for the quick answer. It doesn't work :( Qt has been added to the import list, it's added in def __init__(self, iface): nothing sadly. Is there another line to add maybe ?

– Leo
3 hours ago















Windows doesn't allow the 'Always on top feature'

– Leo
3 hours ago





Windows doesn't allow the 'Always on top feature'

– Leo
3 hours ago













It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

– xunilk
2 hours ago





It is 'init' method of main plugin file (not init.py file of plugin). It works perfectly in my Windows 10.

– xunilk
2 hours ago













By the way, what windows do you use?

– xunilk
2 hours ago





By the way, what windows do you use?

– xunilk
2 hours ago













Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

– Leo
2 hours ago







Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.

– Leo
2 hours ago




















draft saved

draft discarded




















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • 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%2fgis.stackexchange.com%2fquestions%2f308494%2fhow-to-keep-qgis-plugins-always-on-top-of-the-main-window%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

Liste der Baudenkmale in Friedland (Mecklenburg)

Single-Malt-Whisky

Czorneboh