pyQt4 QTabWidget setMovable 与自定义 QTabBar 崩溃
我正在尝试制作一个带有可移动自定义选项卡栏的选项卡小部件。如果我没有子类 QTabBar
和 setMovable(True)
,该程序可以正常工作,但我需要访问 QTabBar< 的
mouseDoubleClickEvent
/code> 因此提供了子分类。当您运行该程序时,一切正常,直到您尝试用鼠标移动选项卡。我觉得我已经尝试了所有可能的 setMovable
组合,但没有任何效果。我做错了什么吗?
使用:
python v2.7.2
PyQt4 v4.8.5
和恶心的Windows XP
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.widgetBox = QHBoxLayout(self)
self.tabs = CTabWidget()
self.widgetBox.addWidget(self.tabs)
self.setLayout(self.widgetBox)
class CTabWidget(QTabWidget):
def __init__(self, parent=None):
super(CTabWidget, self).__init__(parent)
self.tabBar = CTabBar(self)
self.tabBar.addTab("Foo")
self.tabBar.addTab("Bar")
self.setTabBar(self.tabBar)
self.setTabPosition(QTabWidget.West)
self.setMovable(True)
class CTabBar(QTabBar):
def __init__(self, parent=None):
super(CTabBar, self).__init__(parent)
self.setMovable(True)
def addTab(self, string):
super(CTabBar, self).addTab(QString(string))
def mouseDoubleClickEvent(self, event):
print "Change name"
class Run(object):
def __init__(self):
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("plastique"))
main = Main()
main.show()
sys.exit(app.exec_())
Run()
I'm trying to make a tab widget with a custom tab bar movable. The program works fine if I don't subclass QTabBar
and setMovable(True)
but I need to access the mouseDoubleClickEvent
that QTabBar
offers thus the sub classing. When you run the program everything works until the point you try and move a tab with the mouse. I feel like I've tried every possible combination of setMovable
I can think of but nothing's working. Am I doing something wrong?
using:
python v2.7.2
PyQt4 v4.8.5
and disgusting Windows XP
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.widgetBox = QHBoxLayout(self)
self.tabs = CTabWidget()
self.widgetBox.addWidget(self.tabs)
self.setLayout(self.widgetBox)
class CTabWidget(QTabWidget):
def __init__(self, parent=None):
super(CTabWidget, self).__init__(parent)
self.tabBar = CTabBar(self)
self.tabBar.addTab("Foo")
self.tabBar.addTab("Bar")
self.setTabBar(self.tabBar)
self.setTabPosition(QTabWidget.West)
self.setMovable(True)
class CTabBar(QTabBar):
def __init__(self, parent=None):
super(CTabBar, self).__init__(parent)
self.setMovable(True)
def addTab(self, string):
super(CTabBar, self).addTab(QString(string))
def mouseDoubleClickEvent(self, event):
print "Change name"
class Run(object):
def __init__(self):
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("plastique"))
main = Main()
main.show()
sys.exit(app.exec_())
Run()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 QTabWidget.addTab 方法添加选项卡,并确保关联每个选项卡都有一个小部件:
Use the QTabWidget.addTab method to add tabs, and make sure you associate a widget with each tab: