How to keep QGIS plugins always on top of the main window?
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
add a comment |
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
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
2 hours ago
add a comment |
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
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
pyqgis display plugins
edited 2 hours ago
Leo
asked 5 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
2 hours ago
add a comment |
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
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
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
2 hours ago
Good for you. Please, consider also mark the question as accepted. Thanks.
– xunilk
2 hours ago
add a comment |
1 Answer
1
active
oldest
votes
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.
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
|
show 3 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
|
show 3 more comments
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.
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
|
show 3 more comments
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.
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.
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
|
show 3 more comments
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– 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
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
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
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
By the way, what windows do you use?
– xunilk
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
Yes I have updated the init method part of the main plugin file. Yes Windows 10 too.
– Leo
3 hours ago
|
show 3 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
2 hours ago