Reputation: 53
def location_on_the_screen(self):
fg = self.frameGeometry()
sbrp = QDesktopWidget().availableGeometry().bottomRight()
fg.moveBottomRight(sbrp)
self.move(fg.topLeft())
I can't place the window in the bottom right corner of the screen. frameGeometry() not working as it should. Help me, please, what can I do?
Upvotes: 5
Views: 25213
Reputation: 21
from PyQt5.QtWidgets import QMainWindow, QLabel
from PyQt5.QtWidgets import QGridLayout, QWidget, QDesktopWidget
#------------------------------
def center_window():
qtRectangle = self.frameGeometry()
centerPoint = QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
#---------------------------------
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.window_center():
widget.show()
app.exec_()
Upvotes: 2
Reputation: 9863
Here's a possible solution for windows:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.setFixedSize(400, 300)
def location_on_the_screen(self):
ag = QDesktopWidget().availableGeometry()
sg = QDesktopWidget().screenGeometry()
widget = self.geometry()
x = ag.width() - widget.width()
y = 2 * ag.height() - sg.height() - widget.height()
self.move(x, y)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.location_on_the_screen()
widget.show()
app.exec_()
Upvotes: 14
Reputation: 2723
I assume that your 'window' is a subclass of QWidget
. If so, the following should fit your needs:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.setFixedSize(400, 300)
def location_on_the_screen(self):
screen = QDesktopWidget().screenGeometry()
widget = self.geometry()
x = screen.width() - widget.width()
y = screen.height() - widget.height()
self.move(x, y)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.location_on_the_screen()
widget.show()
app.exec_()
Upvotes: 0