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












2















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
    Jan 14 at 4:36






  • 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
    Jan 14 at 4:38











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

    – xunilk
    Jan 14 at 4:41













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

    – Leo
    Jan 14 at 4:49











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

    – xunilk
    Jan 14 at 5:04
















2















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
    Jan 14 at 4:36






  • 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
    Jan 14 at 4:38











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

    – xunilk
    Jan 14 at 4:41













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

    – Leo
    Jan 14 at 4:49











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

    – xunilk
    Jan 14 at 5:04














2












2








2


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 Jan 14 at 4:59







Leo

















asked Jan 14 at 2:03









LeoLeo

1379




1379













  • 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
    Jan 14 at 4:36






  • 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
    Jan 14 at 4:38











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

    – xunilk
    Jan 14 at 4:41













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

    – Leo
    Jan 14 at 4:49











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

    – xunilk
    Jan 14 at 5:04



















  • 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
    Jan 14 at 4:36






  • 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
    Jan 14 at 4:38











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

    – xunilk
    Jan 14 at 4:41













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

    – Leo
    Jan 14 at 4:49











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

    – xunilk
    Jan 14 at 5:04

















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
Jan 14 at 4:36





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
Jan 14 at 4:36




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
Jan 14 at 4:38





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
Jan 14 at 4:38













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

– xunilk
Jan 14 at 4:41







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

– xunilk
Jan 14 at 4:41















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

– Leo
Jan 14 at 4:49





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

– Leo
Jan 14 at 4:49













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

– xunilk
Jan 14 at 5:04





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

– xunilk
Jan 14 at 5:04










1 Answer
1






active

oldest

votes


















3














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
    Jan 14 at 3:44













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

    – Leo
    Jan 14 at 3:46











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

    – xunilk
    Jan 14 at 4:03











  • By the way, what windows do you use?

    – xunilk
    Jan 14 at 4:06











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

    – Leo
    Jan 14 at 4:10













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









3














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
    Jan 14 at 3:44













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

    – Leo
    Jan 14 at 3:46











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

    – xunilk
    Jan 14 at 4:03











  • By the way, what windows do you use?

    – xunilk
    Jan 14 at 4:06











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

    – Leo
    Jan 14 at 4:10


















3














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
    Jan 14 at 3:44













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

    – Leo
    Jan 14 at 3:46











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

    – xunilk
    Jan 14 at 4:03











  • By the way, what windows do you use?

    – xunilk
    Jan 14 at 4:06











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

    – Leo
    Jan 14 at 4:10
















3












3








3







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 Jan 14 at 3:29









xunilkxunilk

14.4k31842




14.4k31842













  • 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
    Jan 14 at 3:44













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

    – Leo
    Jan 14 at 3:46











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

    – xunilk
    Jan 14 at 4:03











  • By the way, what windows do you use?

    – xunilk
    Jan 14 at 4:06











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

    – Leo
    Jan 14 at 4:10





















  • 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
    Jan 14 at 3:44













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

    – Leo
    Jan 14 at 3:46











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

    – xunilk
    Jan 14 at 4:03











  • By the way, what windows do you use?

    – xunilk
    Jan 14 at 4:06











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

    – Leo
    Jan 14 at 4:10



















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
Jan 14 at 3:44







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
Jan 14 at 3:44















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

– Leo
Jan 14 at 3:46





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

– Leo
Jan 14 at 3:46













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

– xunilk
Jan 14 at 4:03





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

– xunilk
Jan 14 at 4:03













By the way, what windows do you use?

– xunilk
Jan 14 at 4:06





By the way, what windows do you use?

– xunilk
Jan 14 at 4:06













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

– Leo
Jan 14 at 4:10







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

– Leo
Jan 14 at 4:10




















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

Mario Kart Wii

The Binding of Isaac: Rebirth/Afterbirth

What does “Dominus providebit” mean?