pyqt qtabwidget关闭_如何防止关闭选项卡QTabWidget?(How to prevent a closing tab QTabWidget? PyQT4)...

本文介绍了如何在PyQT4中防止QTabWidget的特定标签页(如'work_1')被关闭。通过连接`tabCloseRequested`信号到`removeTab`方法,可以关闭除'work_1'之外的所有标签页。解决方案是通过窗口小部件的`objectName`或其他唯一属性来识别标签页,而不是依赖于可能会变化的索引。
摘要由CSDN通过智能技术生成

如何防止关闭选项卡QTabWidget?(How to prevent a closing tab QTabWidget? PyQT4)

使用此代码:

QtCore.QObject.connect(self.tabWidget, QtCore.SIGNAL("tabCloseRequested(int)"),

self.tabWidget.removeTab)

我可以关闭任何标签QTabWidget,这些标签的名称是:

work_1

work_2

work_3

但我希望标签work_1永远不会关闭。

使用索引不起作用有两个原因:

可以通过以下代码动态移动选项卡:self.tabWidget.setMovable (True)

这使得指数不断变化。

用户可以添加新选项卡。

With this code:

QtCore.QObject.connect(self.tabWidget, QtCore.SIGNAL("tabCloseRequested(int)"),

self.tabWidget.removeTab)

I can close any tab QTabWidget, and the names of these tabs are:

work_1

work_2

work_3

But I want the tab work_1 never closes.

Use Index did not work for two reasons:

The tabs can be dynamically moved by this code: self.tabWidget.setMovable (True)

That makes the Index are constantly changing.

The user has the ability to add new tabs.

原文:https://stackoverflow.com/questions/36121387

2020-02-20 20:51

满意答案

选项卡可以通过其窗口小部件进行标识,窗口小部件可以通过其objectName (或其他一些唯一属性)进行标识:

self.tabWidget.tabCloseRequested.connect(sef.removeTab)

...

def removeTab(self, index):

widget = self.tabWidget.widget(index)

if widget is not None and widget.objectName() != 'work_1':

self.tabWidget.removeTab(index)

或者更简单:

if widget is not None and widget is not self.work_1:

self.tabWidget.removeTab(index)

Tabs can be identified by their widgets, and the widgets can be identified by their objectName (or some other unique attribute):

self.tabWidget.tabCloseRequested.connect(sef.removeTab)

...

def removeTab(self, index):

widget = self.tabWidget.widget(index)

if widget is not None and widget.objectName() != 'work_1':

self.tabWidget.removeTab(index)

or perhaps more simply:

if widget is not None and widget is not self.work_1:

self.tabWidget.removeTab(index)

2016-03-21

相关问答

好的,我发现了自己的问题。 我把self.ui.tabWidget.tabCloseRequested.connect(self.onTabClose)放在与创建新标签的方法相同的方法中。 这意味着如果创建了5个选项卡,那么当一个选项卡关闭时,tabCloseReqested会触发5次。 通过将此连接语句放在我的类的init中,就像我应该做的那样,它只定义一次,并且仅在关闭选项卡时触发一次。 OK, I found the problem my self. I had put the self.u...

很惊讶地看到这还没有回答。 有一段时间,我已经实施了一个工作示例。 请注意,我没有使用其中一个选项卡作为“+”按钮,而是使用了QToolButton因此可以更简单地使用QTabWidget::setTabsClosable(bool)使标签可以关闭 mainwindow.h #ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include

#include

#include

#i...

使用myTabWidget->widget(index) 。 每个标签都有一个。 文件 如果类继承自QObject ,或者将其信号(如destroyed() )与类的信号连接,则可以将窗口小部件设置为类的父级。 或者你甚至可以做到 QVariant prop = QVariant::fromValue((intptr_t)workerObject);

myTabWidget->widget(index)->setProperty("workerObject", prop);

...

您必须使用addTab()函数,但要从另一个类中执行此操作, QTabWidget对象必须是该类的成员。 此外,我还对设计进行了一些更改,因为按钮位于QTabWidget ,覆盖了选项卡。 from PyQt5 import QtCore, QtGui, QtWidgets

import sys

class mainForm(QtWidgets.QWidget):

def __init__(self):

super().__init__()

self.ru...

其实我只选择了QTabWidget的子类。 在创建新选项卡时添加checkBox并将其保存到列表中以便返回其索引。 setCheckState / isChecked方法旨在控制其tab选项卡指定的每个checkBox的状态。 最后,捕获“stateChanged(int)”信号并使用指定相关checkBox索引的额外参数进行重新传递。 class CheckableTabWidget(QtGui.QTabWidget):

checkBoxList = []

def addTa...

可以通过tab-widget的tabBar方法设置选项卡文本颜色: tabwidget.tabBar().setTabTextColor(index, color)

The tab text color can be set via the tab-widget's tabBar method: tabwidget.tabBar().setTabTextColor(index, color)

您可以使用QTabWidget的widget功能来获取指定标签索引处的小部件。 如果QPlainTextEdit是每个标签页唯一的小部件,那么返回的小部件就是那个。 否则,您需要获取小部件的子项并在其中找到QPlainTextEdit 。 QPlainTextEdit* pTextEdit = NULL;

QWidget* pWidget= ui->tabWidget->widget(1); // for the second tab

// You can use metaobject to ge...

选项卡可以通过其窗口小部件进行标识,窗口小部件可以通过其objectName (或其他一些唯一属性)进行标识: self.tabWidget.tabCloseRequested.connect(sef.removeTab)

...

def removeTab(self, index):

widget = self.tabWidget.widget(index)

if widget is not None and widget...

看看QTabBar的源代码( QTabBar子元素),似乎这是不可能的。 所有选项卡只有一个movable属性。 但是,您可以尝试以下方法: 子类QTabBar并在拖动开始之前捕获鼠标按下事件以启用或禁用选项卡的移动。 像这样的东西: void MyTabBar::mousePressEvent(QMouseEvent *event) {

// all tabs movable except first

setMovable(tabAt(event->pos()) != 0);

...

改变这个: QWidget* pWidget = new QWidget(this);

QSplitter* pSplitter = new QSplitter(pWidget);

对此: QWidget* pWidget = new QWidget(this);

QVBoxLayout* layout = new QVBoxLayout(pWidget);

QSplitter* pSplitter = new QSplitter(pWidget);

layout->addWidget(pSpl...

相关文章

请看图 问题是tab选项卡怎么能在右边而不在左边!

参考开源项目PagerSlidingTabStrip 做了一些小修改,比如设置Tab页平均铺满效果、

...

请问Ext4.1 Tab组件,如何实现双击页签关闭功能?

参考开源项目PagerSlidingTabStrip 做了一些小修改,比如设置Tab页平均铺满效果、字

...

pro-du-cer n. 1. Someone from a game publisher who

...

With an executive staffing venture about to open, a

...

http://gumstix.org/create-a-bootable-microsd-card.h

...

Hibernate exception - Illegal attempt to associate

...

如题,应该有当前tab数的api,但是我看文档没有找到,知道的指点下

启动android模拟器时.有时会报The connection to adb is down, an

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值