私はアプリケーションインタフェースとしてPyQt4.QMainWindowを使用しています。マウスのx座標とy座標をQWidget内で取得し、それらを2つのtextBrowserで連続して設定したいとします。 MainWindow。QWidgetでPyQt4.QtGui.QMouseEventを使用する
QWidgetのドキュメントはhereです。
とQMouseEventのドキュメントはhereです。ここで
あなたは手動でなければならないので、それが唯一の次の溶液中で、そのウィジェットのではなく、あなたの子供に適用されますsetMouseTracking適用すると、コード
from PyQt4 import QtGui
from PyQt4.QtGui import QApplication
import sys
class Ui_MainWindow(object):
def setupUI(self, MainWindow):
self.textBrowser_1 = QtGui.QTextBrowser(self.tab)
self.textBrowser_2 = QtGui.QTextBrowser(self.tab)
self.widget_1 = QtGui.QWidget(self.tab)
self.widget_1.setMouseTracking(True)
class MyMainScreen(QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow() # This is from a python export from QtDesigner
# There is a QWidget inside that is self.ui.widget_1
# and 2 textBrowsers, textBrowser_1 and textBrowser_2
# I want to populate these 2 textBrowsers with the current x,y
# coordinates.
if __name__ == "__main__":
app = QApplication(sys.argv)
mainscreen = MyMainScreen()
mainscreen.show()
app.exec_()
私の解決策を試してください – eyllanesc
あなたはQtについてよく知らないようです。 MouseMoveEventは、マウスがウィジェット内を移動するたびにフレームワークから呼び出されるイベントコールバックです。これはおそらくあなたが持っているものですが、それを呼び出す代わりに(それは理にかなっていません)、おそらくそれをオーバーライドしてそこで独自のアクションを実装したいと考えています。 – Trilarion
[PyQt4を使用すると、QMainWindowではQWidget内でのみ動作するようにmouseMoveEventを設定しますが、MainWindowでは動作させないようにするにはどうすればよいですか?(http://stackoverflow.com/questions/40878157/using-pyqt4-how-do -you-set-a-mousemoveevent-to-only-work-a-qwidget-in) –