创建TAB并创建用于在TAB页中获取数据的文本框 [英] Create TAB and create textboxes that take data in the TAB-page

查看:88
本文介绍了创建TAB并创建用于在TAB页中获取数据的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PyQt工作。现有的代码(非常长,几乎可以获取所有组织的代码)都包含一些部分,这些部分负责创建标签和文本框。但是,作为PyQt的新手,我不清楚这一切如何工作。就我而言,我需要执行以下操作:
(1)在所有其他标签的行中创建一个名为 xyz的TAB。
(2)在页面上创建6个带有单独标签的文本框,由创建的TAB显示,用户可以在其中输入数据并保存。

I am working in PyQt. The existing code (extremely long and sources almost all the org.'s s/w) has sections which is responsible for creating tabs and textboxes. But, being a newbie to PyQt, I am not clear on how it all works. For my part, I need to do the following: (1) Create a TAB titled 'xyz' within the row of all the other tabs. (2) Create 6 textboxes with individual labels in the page displyed by the created TAB where the user can enter data and save it.

这是两个我现在必须处理的眼前问题。稍后,

These are the two immediate problems I have to deal with now. Later,

一旦输入并保存了文本框中的数据,在文本框中输入的数据将替换条形图(在另一个窗口中)中的数据。这将在之后完成,但是首先我需要解决上面列出的2个问题。导入都在(冗长的)代码中,我必须在代码中插入新代码-也许可以通过创建一个新类。你能帮我吗?谢谢。并且,如果您需要任何信息来解决此问题,请告诉我。

The data entered in the textboxes will replace the data in bar-graphs (in another window) as soon as the data in the textboxes is entered and saved. This is to be done afterwards but first I need to solve the 2 issues listed above. The imports are all there in the (longish) code and I have to insert my new code within that code - perhaps by creating a new class. Can you help? Thanks. And, please let me know if you need any information to work on this.

:::::::::::已插入下面的图像。如您所见,在左窗格的顶部,一行中有多个选项卡(全部在PyQt中制作)。我需要创建一个选项卡,如上一个选项卡(此处为标题激励),其空白页类似于该选项卡下方显示的页面。在页面中,我需要创建2组文本框,每组3个文本框,并分别带有该组和各个文本框的标签。在框中输入的数据将是整数(20),然后该数据将继续填充/更新动态堆叠的条形图。在这一点上,我想问另一个问题。数据更新图形时,应先将其保存在数据库(主要负责图形中初始图形的数据库)中,然后路由至图形,还是应绕过数据库直接更新图形,或者因此,一旦重置,图形就不会恢复为先前的值,也不会忘记文本框中的数据。谢谢。

:::::::::: Have inserted the image below. As you can see, at the top of the left pane, there are multiple tabs in a row (all made in PyQt). I need to create a tab like the last one (here, titled-Incentives) with a blank page like the one shown below the tab. Within the page, I need to create 2 sets of textboxes, 3 textboxes in each set with labels for the set(s) and the individual textboxes. Data entered in the boxes will be integers(20) and the data will then go on to populate/update a dynamic stacked bar graph. At this point, I want to ask another question. When the data updates the graph, should it be first saved in the DB (the DB which is primarily responsible for the initial figures in the graph) and then routed to the graph or should the data update the graph directly, bypassing the DB and if so, won't the graph revert to its earlier values and forget the data from the textboxes once it is reset. Thank you.

推荐答案

好的。在这里,您可以使用代码作为自己开发的起点。它创建带有两个选项卡的 QTabWidget 。 选项卡1选项卡包含带有两个组框的垂直布局。组框包含排列在网格中的标签和文本框。另一个选项卡为空。

OK. Here you have a code that you can use as a starting point for your own development. It creates a QTabWidget with two tabs. The "Tab 1" tab contains a vertical layout with two groupboxes. Groupboxes contain labels and textboxes arranged in a grid. The other tab is empty.

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MyMainWindow(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)

        # Create the tabbed widget
        self.central = QTabWidget(self)
        self.setCentralWidget(self.central)

        # Create a new tab
        self.tab1 = QWidget()
        # Tab has a vertical layout
        self.vbox = QVBoxLayout(self.tab1)
        # Tab children: two groups containing a grid of labels and textboxes
        self.group1 = QGroupBox("Group 1")
        self.textBox1 = QLineEdit(self.group1)
        self.textBox2 = QLineEdit(self.group1)
        self.fillGroup(self.group1, self.textBox1, self.textBox2)
        self.group2 = QGroupBox("Group 2")
        self.textBox3 = QLineEdit(self.group2)
        self.textBox4 = QLineEdit(self.group2)
        self.fillGroup(self.group2, self.textBox3, self.textBox4)
        # Add tab children to the tab layout
        self.vbox.addWidget(self.group1)
        self.vbox.addWidget(self.group2)
        # Append tab to the tabbed widget
        self.central.addTab(self.tab1, "Tab 1")

        # Create a new tab and append it to the tabbed widget
        self.tab2 = QWidget()
        self.central.addTab(self.tab2, "Tab 2")

    def fillGroup(self, group, box1, box2) :
        """Arrange the groupbox content in a grid layout"""

        grid = QGridLayout(group)
        label1 = QLabel("Input 1:", group)
        grid.addWidget(label1, 0, 0)
        grid.addWidget(box1, 0, 1)
        label2 = QLabel("Input 2:", self.group1)
        grid.addWidget(label2, 1, 0)
        grid.addWidget(box2, 1, 1)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    ui = MyMainWindow()
    ui.show()
    sys.exit(app.exec_())

请注意,为方便起见,我将 QMainWindow 用作选项卡式小部件的父级。显然,如果需要,您可以将其他小部件用作父级。

Please notice that for my convenience I've used a QMainWindow as a parent for the tabbed widget. Obiously you can use other widgets as parent if you need it.

希望它会有所帮助。

这篇关于创建TAB并创建用于在TAB页中获取数据的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆