Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否有一个PyQt表/列表视图可以在其中一列中用组合框动态填充?_Python_Pyqt_Pyqt4_Qgis - Fatal编程技术网

Python 是否有一个PyQt表/列表视图可以在其中一列中用组合框动态填充?

Python 是否有一个PyQt表/列表视图可以在其中一列中用组合框动态填充?,python,pyqt,pyqt4,qgis,Python,Pyqt,Pyqt4,Qgis,我正在使用PyQt作为qgis插件。我想要一种表/列表视图,第一列是打开的shapefile中的层,第二列是将从数据库输入中加载值的组合框。这可能吗?如果可能,我需要使用listview、tableview或treeview吗?提前谢谢 如果我理解你的话,我刚才也做过类似的事情 在我的例子中,我想用QdoubleSpinbox填充下面的QTableWidget,并为每个QdoubleSpinbox设置特定的属性 因此,我在QDesigner中创建了一个“model”空QTableWidget,

我正在使用PyQt作为qgis插件。我想要一种表/列表视图,第一列是打开的shapefile中的层,第二列是将从数据库输入中加载值的组合框。这可能吗?如果可能,我需要使用listview、tableview或treeview吗?提前谢谢

如果我理解你的话,我刚才也做过类似的事情

在我的例子中,我想用QdoubleSpinbox填充下面的QTableWidget,并为每个QdoubleSpinbox设置特定的属性

因此,我在QDesigner中创建了一个“model”空QTableWidget,并在代码中使用了以下函数:

填充QTableWidget 我不知道您正在阅读的文件的格式是什么,但我确信您可以在我的函数中添加一个
for
循环,以便根据文件中的条目将值设置到QDoubleSpinBox。此外,还可以使用
setVerticalHeaderLabels
setHorizontalHeaderLabels
方法通过代码设置标题标签

尽管我使用pyqt,但我通常使用pyside的文档,因为它们在大多数情况下是相等的,pyside的文档更易于阅读和浏览。


希望能有所帮助。

非常有帮助!谢谢大家!@InsertDisplayName。。。那么你可以接受答案,不?
def QTableWidget_populate(self, table):
    # Create an empty matrix with the same dimensions as your table
    self.ele_mat = [
        [0 for x in range(table.columnCount())] for x in range(table.rowCount())]
    # For each cell in the table define its characteristics
    for row in xrange(table.rowCount()):
        for column in xrange(table.columnCount()):
            # Define row name prefix
            if row == 0:
                element = 'Begin_'
            elif row == 1:
                element = 'MidMinus_'
            elif row == 2:
                element = 'MidPlus_'
            elif row == 3:
                element = 'End_'

            # Define columns paraters
            if column == 0:
                element += 'Pow'    # Name column sufix
                param1 = '2'        # setDecimals settings
                param2 = '-99,99'   # setRange
                param3 = '"dBm"'    # seSuffix
            elif column == 1:
                element += 'PD'
                param1 = '0'
                param2 = '0,999'
                param3 = '"uA"'
            elif column == 2:
                element += 'TMVoltage'
                param1 = '2'
                param2 = '-99,99'
                param3 = '"V"'
            elif column == 3:
                element += 'Wav'
                param1 = '1'
                param2 = '0,2000'
                param3 = '"nm"'
            # Popule matrix with dict of parameters
            self.ele_mat[row][column] = {
                'name': element, 'type': 'QtGui.QDoubleSpinBox()',
                                         'Adjustments': ['setDecimals', 'setRange', 'setSuffix'],
                                         'Params':  [param1, param2, param3]}
    # Using the matrix populate the QTableWidget                                  
    for row in xrange(table.rowCount()):
        for column in xrange(table.columnCount()):
            # Create Widget with name and type defined in the matrix
            exec('self.{} = {}' .format(
                self.ele_mat[row][column]['name'],
                self.ele_mat[row][column]['type']))

            # Give it its settings
            for adjustment, param in zip(self.ele_mat[row][column]['Adjustments'],
                                         self.ele_mat[row][column]['Params']):
                exec('self.{}.{}({})' .format(self.ele_mat[
                     row][column]['name'], adjustment, param))

            # Set the created widget to the QTableWidget
            table.setCellWidget(row, column, eval(
                'self.{}' .format(self.ele_mat[row][column]['name'])))

    # For better clarity in GUI
    table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
    table.verticalHeader().setResizeMode(QtGui.QHeaderView.Stretch)