PyQt Rowspan问题

时间:2014-11-23 16:30:50

标签: python python-3.x textbox pyqt4

我正在使用PyQt为爱尔兰词典搜索器创建GUI。我已经在tkinter中完成了它,但是听说PyQt要好得多,路要走,所以我也想开发它的一个版本。我差不多完成了,除了我有问题。我正在创建一个双语版本,爱尔兰语和英语,但我希望两个版本都使用相同的文本小部件,因此您可以在任一版本中看到您调用的单词。但是,它不会出现在第二个中,即使它已添加到rid中,所以我不得不在我的交换机回调中删除/添加它。但是,在我这样做之后,尽管在rowspan上有多个设置,但它没有显示正确的大小。附上相关代码。在EnglishVersion类中启动时出现的网格工作得很好(尽管如果我可以让它变得更大,因为很多文本会被呈现),但是在我切换版本后它变得太小了有用。

编辑:根据要求仅包含问题的新代码

import sys
from PyQt4 import QtGui, QtCore


class Callback(): 
    def remove():
        foo.hide()
        bar.show()
        foo.layout().removeWidget(foo.text_entry)
        bar.layout().addWidget(bar.text_entry, 1, 0, 24, 2)

class Text(QtGui.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.text_entry = QtGui.QTextEdit(parent)


class Foo(QtGui.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.text_entry = text.text_entry
        self.button = QtGui.QPushButton("Remove and readd text")
        self.button.clicked.connect(lambda: Callback.remove())

        grid = QtGui.QGridLayout()
        grid.addWidget(self.button, 0, 0, 1, 2)
        grid.addWidget(self.text_entry, 1, 0, 24, 2)
        self.setLayout(grid)


class Bar(QtGui.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.text_entry = text.text_entry
        self.button = QtGui.QPushButton("After it has been pushed")
        grid = QtGui.QGridLayout()
        grid.addWidget(self.button, 0, 0, 1, 2)
        self.setLayout(grid)




app = QtGui.QApplication(sys.argv)
text = Text()
foo = Foo()
bar = Bar()
foo.show()
app.exec_()

0 个答案:

没有答案