qtabbar禁用滚轮切换
时间: 2024-09-09 15:07:06 浏览: 76
要禁用QTabBar(QT的水平选项卡栏控件)的滚轮切换功能,你可以通过设置`QAbstractItemView`的滚动模式来实现。在PyQt5中,这通常是在创建或配置QTabBar时完成的。具体操作如下:
```python
from PyQt5.QtWidgets import QApplication, QTabBar, QVBoxLayout, QWidget
from PyQt5.QtCore import Qt
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.tab_bar = QTabBar()
self.tab_bar.setAcceptDrops(True) # 取消滚轮切换,保持默认行为
self.tab_bar.setScrollMode(QAbstractItemView.ScrollPerPixel)
layout = QVBoxLayout()
layout.addWidget(self.tab_bar)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication([])
window = MyWindow()
window.show()
app.exec_()
```
在这个例子中,我们设置了`setScrollMode()`方法为`QAbstractItemView.ScrollPerPixel`,这意味着滚动条只会在单击事件下响应,滚轮滚动不会改变当前选中的选项。
阅读全文
相关推荐
















