У меня есть большая карта, которая находится внутри прокручиваемой области.То, что я хочу, - это нажать на название страны, название которой - PyQt5 QPushButton.Теперь у меня есть кнопка, которая остается на том же месте по отношению к экрану, но не к карте:
import sys
from PyQt5.QtGui import QPixmap, QPalette
from PyQt5.QtWidgets import QApplication, QScrollArea, QLabel, QPushButton
class MapGUI(QScrollArea):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
screen_resolution = app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
self.setGeometry(0, 0, height, height)
self.setWindowTitle("The World")
self.label = QLabel()
self.pixmap_unscaled = QPixmap("The_World.png")
# Scaling the image to half the size
self.pixmap = self.pixmap_unscaled.scaled(int(self.pixmap_unscaled.width() * 0.5), int(self.pixmap_unscaled.height() * 0.5))
self.label.setPixmap(self.pixmap)
self.button = QPushButton('PyQt5 button', self)
self.button.setToolTip('This is an example button')
self.button.setGeometry(100, 100, 100, 50)
self.setBackgroundRole(QPalette.Dark)
self.setWidget(self.label)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
map = MapGUI()
sys.exit(app.exec_())
При этом кнопка статична.Есть ли способ связать движение карты с движением кнопки, чтобы при прокрутке кнопка следовала за ней?