当前位置: 首页>>代码示例>>Python>>正文


Python QTableView.setAlternatingRowColors方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setAlternatingRowColors方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setAlternatingRowColors方法的具体用法?Python QTableView.setAlternatingRowColors怎么用?Python QTableView.setAlternatingRowColors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QTableView的用法示例。


在下文中一共展示了QTableView.setAlternatingRowColors方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InvertedTable

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]
class InvertedTable(SQLTable):
    """a Widget that displays content of an SQLite query inverted
    (= with rows and columns flipped);
    """
    def __init__(self, log, mydb = ": memory :", add_color_proxy = False):
        self.add_color_proxy = add_color_proxy
        super().__init__(log, mydb)
        self.fill_UI()
        
    def fill_UI(self):
        """sets up the layout
        """
        self.table = QTableView()
        header = self.table.horizontalHeader()
        header.hide()
        header.setStretchLastSection(True)
        self.table.resizeColumnsToContents()
        self.table.setAlternatingRowColors(True)
        self.grid.addWidget(self.table, 1, 0)
        self.log.debug("\t=> Table created!")
    
    def invert_model(self):
        """inverts the model for the table
        """
        self.flipped_model = GUI_flipped.FlippedProxyModel()
        if self.model:
            self.log.debug("Creating the flipped model...")
            if self.add_color_proxy:
                (allele_status_column, lab_status_column) = self.add_color_proxy
                self.log.debug("adding status color background to columns {} and {}".format(allele_status_column, lab_status_column))
                self.color_proxy = ColorProxyModel(self, allele_status_column, lab_status_column)
                self.color_proxy.setSourceModel(self.model)
                self.flipped_model.setSourceModel(self.color_proxy)
            else:
                self.flipped_model.setSourceModel(self.model)
            self.table.setModel(self.flipped_model)
            self.table.setItemDelegate(GUI_flipped.FlippedProxyDelegate(self.table)) # use flipped proxy delegate
            self.log.debug("\t=> Model created")
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:40,代码来源:GUI_overviews.py

示例2: CharView

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]

#.........这里部分代码省略.........
        # to the view so it can query the row under the mouse.
        self.model = CharModel(self.chardata,self)
        #Interpose a sort filter proxy between the view and the model.
        self.proxy = CharFilter(self.chardata,self)
        self.proxy.setSourceModel(self.model)
        self.view.setModel(self.proxy)
        # Hook up some signals.
        # Connect the double-click signal to find_this.
        self.view.doubleClicked.connect(self.find_this)
        # Connect the CharsLoaded from the chardata object to our slot.
        self.chardata.CharsLoaded.connect(self.chars_loaded)
        # Connect the popup activated signal to our slot.
        self.popup.activated.connect(self.new_filter)
        # Connect the refresh button clicked signal to refresh below
        self.refresh.clicked.connect(self.do_refresh)
        # Connect the modelReset signal to our slot.
        self.model.modelReset.connect(self.set_up_view)

    # Slot to receive doubleClicked(index) from the table view, and
    # convert that into a Find for that character.
    def find_this(self, index):
        repl = None
        if index.column() == 3 :
            # doubleclick was in the HTML entity column. Put the entity
            # string from column 3 in the replace-1 field
            repl = index.data(Qt.DisplayRole)
        if index.column() != 0 :
            # dblclick on some column other than 0. We need a reference to
            # column 0, and we get it from the index.
            index = index.sibling(index.row(),0)
        what = index.data(Qt.DisplayRole) # get the character as a string
        # Call for a find with respect case on, whole word and regex off
        self.findpanel.find_this(what,case=True,word=False,regex=False,repl=repl)

    # Slot to receive the CharsLoaded() signal from the chardata module
    # (metadata has been loaded). Reset the table model.
    def chars_loaded(self):
        self.model.beginResetModel()
        self.model.endResetModel()

    # Slot to receive the activated(row) signal from the filter popup. Set
    # the filter and reset the table model.
    def new_filter(self,row):
        self.model.beginResetModel()
        self.proxy.set_filter(row)
        self.model.endResetModel()

    # Slot to receive the clicked() signal from the Refresh button.
    # Warn the table model that things be changing, then call the
    # database to do a new census, then finish the table reset.
    def do_refresh(self):
        self.model.beginResetModel()
        self.chardata.refresh()
        self.model.endResetModel()

    # Slot to receive the modelReset() signal from the table model, emitted
    # after the endResetModel() call. Set some features of our table view
    # that we can't set until some data has been loaded.
    def set_up_view(self):
        self.view.resizeColumnsToContents()
        self.view.horizontalHeader().setStretchLastSection(True)
        self.view.resizeRowsToContents()
        self.view.setSortingEnabled(True)

    # Do all the fiddly UI stuff out of line.
    def _uic(self):
        mainLayout = QVBoxLayout()
        self.setLayout(mainLayout)
        topLayout = QHBoxLayout()
        topLayout.setContentsMargins(0,0,0,0)
        mainLayout.addLayout(topLayout,0)
        # Lay out the refresh button and filter popup
        self.refresh = QPushButton(
            _TR('Button to reload all data in char panel',
                'Refresh')
            )
        topLayout.addWidget(self.refresh,0)
        topLayout.addStretch(1) # push filters to the right
        self.popup = QComboBox()
        # Set choices in popup, must match to the lambdas
        # defined in CharFilter.set_filter()
        self.popup.addItem(
            _TR('char panel: show all characters',
                'All')
        )
        self.popup.addItem(
            _TR('char panel: show non-ascii characters',
                'not 7-bit')
        )
        self.popup.addItem(
            _TR('char panel: show non-latin-1',
                'not Latin-1')
        )
        topLayout.addWidget(self.popup,0)
        # Set up the table view, the actual visible table
        self.view = QTableView()
        self.view.setCornerButtonEnabled(False)
        self.view.setWordWrap(False)
        self.view.setAlternatingRowColors(True)
        mainLayout.addWidget(self.view,1) # give it all the stretch
开发者ID:B-Rich,项目名称:PPQT2,代码行数:104,代码来源:charview.py

示例3: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]
class MainWindow(QMainWindow):

    def __init__(self, data):
        super().__init__()

        self.resize(400, 600)
        self.setWindowTitle('Logger Skeleton')
        self.statusBar().showMessage("Ready", 2000)

        # Make widgets ####################################

        self.tabs = QTabWidget(self)
        self.setCentralWidget(self.tabs)

        # Add tabs
        self.table_tab = QWidget(self)
        self.stats_tab = QWidget(self)

        self.tabs.addTab(self.table_tab, "Table")
        self.tabs.addTab(self.stats_tab, "Stats")

        # Table tab ###########################################################

        self.table_view = QTableView(self.table_tab)
        self.text_edit = QPlainTextEdit()
        self.btn_add_row = QPushButton("Add a row")
        #self.btn_remove_row = QPushButton("Remove selected rows")

        table_tab_vbox = QVBoxLayout()

        table_tab_vbox.addWidget(self.table_view)
        table_tab_vbox.addWidget(self.text_edit)
        table_tab_vbox.addWidget(self.btn_add_row)
        #table_tab_vbox.addWidget(self.btn_remove_row)

        self.table_tab.setLayout(table_tab_vbox)

        # Set model #######################################

        my_model = DataQtModel(data, parent=self)  # TODO: right use of "parent" ?

        # Proxy model #####################################

        proxy_model = QSortFilterProxyModel(parent=self)  # TODO: right use of "parent" ?
        proxy_model.setSourceModel(my_model)

        self.table_view.setModel(proxy_model)
        #self.table_view.setModel(my_model)

        # Set the view ####################################

        self.table_view.setSelectionBehavior(QAbstractItemView.SelectRows)    # Select the full row when a cell is selected (See http://doc.qt.io/qt-5/qabstractitemview.html#selectionBehavior-prop )
        #self.table_view.setSelectionMode(QAbstractItemView.SingleSelection)  # Set selection mode. See http://doc.qt.io/qt-5/qabstractitemview.html#selectionMode-prop

        self.table_view.setAlternatingRowColors(True)
        self.table_view.setSortingEnabled(True)
        self.table_view.setColumnWidth(0, 200)                       # TODO: automatically get the best width

        self.table_view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)    # https://stackoverflow.com/q/17535563

        self.table_view.setColumnHidden(COMMENT_COLUMN_INDEX, True)

        delegate = Delegate()
        self.table_view.setItemDelegate(delegate)

        # Set key shortcut ################################

        # see https://stackoverflow.com/a/17631703  and  http://doc.qt.io/qt-5/qaction.html#details

        # Add row action

        add_action = QAction(self.table_view)
        add_action.setShortcut(Qt.CTRL | Qt.Key_N)

        add_action.triggered.connect(self.add_row_btn_callback)
        self.table_view.addAction(add_action)

        # Delete action

        del_action = QAction(self.table_view)
        del_action.setShortcut(Qt.Key_Delete)

        del_action.triggered.connect(self.remove_row_callback)
        self.table_view.addAction(del_action)

        # Set QDataWidgetMapper ###########################

        self.mapper = QDataWidgetMapper()
        self.mapper.setModel(proxy_model)          # WARNING: do not use `my_model` here otherwise the index mapping will be wrong!
        self.mapper.addMapping(self.text_edit, COMMENT_COLUMN_INDEX)
        self.mapper.toFirst()                      # TODO: is it a good idea ?

        self.table_view.selectionModel().selectionChanged.connect(self.update_selection)

        # Set slots #######################################

        self.btn_add_row.clicked.connect(self.add_row_btn_callback)
        #self.btn_remove_row.clicked.connect(self.remove_row_callback)

        #self.table_view.setColumnHidden(1, True)
#.........这里部分代码省略.........
开发者ID:jeremiedecock,项目名称:snippets,代码行数:103,代码来源:app_skeleton_logger.py

示例4: ExportFrame

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]
class ExportFrame(QFrame):
    def get_existing_resync_file(self, resync_file):
        # get the existing resync_file as file URI.
        # return 'file://'+self.config.get_cfg_resync_dir()+'/'+resync_file
        p = PurePath(self.config.cfg_resync_dir(), resync_file)
        return p.as_uri()

    def __init__(self, parent):
        super().__init__(parent)
        self.logger = logging.getLogger(__name__)
        self.config = Configuration()
        self.filenames = []
        self.data = ""

        # left part of frame
        header_left = [_("Relative Path"), _("Name"), _("Size"), _("Date Modified")]
        self.file_model = FileTableModel(self, header_left, [])

        self.file_view = QTableView()
        self.file_view.setModel(self.file_model)
        self.file_view.setSortingEnabled(True)
        self.file_view.setAlternatingRowColors(True)
        self.file_view.setShowGrid(False)

        # adjustments
        self.file_view.verticalHeader().setDefaultSectionSize(22)
        # self.file_view.horizontalHeader().setDefaultSectionSize(self.file_view.width()/len(header))
        # self.file_view.horizontalHeader().setStretchLastSection(True)
        self.file_view.setSelectionMode(QAbstractItemView.SingleSelection)
        self.file_view.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.file_view.doubleClicked.connect(self.file_view_doubleclicked)
        # self.file_view.clicked.connect(self.file_view_clicked)
        self.file_view.selectionModel().selectionChanged.connect(self.file_view_selection_changed)
        # self.file_view.setContextMenuPolicy(Qt.CustomContextMenu)
        # self.file_view.customContextMenuRequested.connect(self.file_view_context_menu_requested)

        # self.lb_nsfc = QLabel("")
        self.lb_path = QLabel("")
        self.lb_path.setFont(QFont("SansSerif", 10))

        self.pb_select = QPushButton(_("Select"))
        self.pb_select.clicked.connect(self.show_explorer)

        # right part of frame
        header_right = [_("Set Name"), _("Files"), _("New Files"), _("Update Files"), _("Unchanged Files")]
        self.overview_model = OverviewTableModel(self, header_right, [])
        self.overview = QTableView()
        self.overview.setModel(self.overview_model)
        self.overview.setAlternatingRowColors(True)
        self.overview.setShowGrid(False)

        self.overview.verticalHeader().setDefaultSectionSize(22)

        self.pb_publish = QPushButton(_("Publish"))
        self.pb_publish.clicked.connect(self.pb_publish_clicked)

        self.pb_zip = QPushButton(_("Create Zip"))
        self.pb_zip.clicked.connect(self.pb_zip_clicked)

        self.__init_ui__()

    def __init_ui__(self):

        vbox = QVBoxLayout()

        splitter = QSplitter()

        splitter.addWidget(self.file_view)
        splitter.addWidget(self.overview)

        vbox.addWidget(splitter, 1)
        vbox.addWidget(self.lb_path)

        button_box = QHBoxLayout()
        button_box.addWidget(self.pb_select)
        button_box.addStretch(1)
        button_box.addWidget(self.pb_publish)
        button_box.addWidget(self.pb_zip)
        vbox.addLayout(button_box)

        self.setLayout(vbox)

    def file_view_doubleclicked(self, index):
        path = self.file_model.full_path(index.row())
        webbrowser.open_new(PurePath(path).as_uri())

    def file_view_clicked(self, index):
        pass

    def file_view_selection_changed(self, selected, deselected):
        # selected, deselected: PyQt5.QtCore.QItemSelection
        sindexes = selected.indexes()
        if len(sindexes) > 0:
            index = sindexes[0]
            path = self.file_model.full_path(index.row())
            self.lb_path.setText(path)
        else:
            self.lb_path.setText("")

#.........这里部分代码省略.........
开发者ID:EHRI,项目名称:resyto,代码行数:103,代码来源:export_frame.py

示例5: FnotePanel

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]

#.........这里部分代码省略.........
                'A Footnote zone is defined by "/F" and "F/" lines.' )
            utilities.warning_msg(emsg,expl,self)
            return
        # create a working cursor and start an undo macro on it.
        worktc = self.edit_view.get_cursor()
        worktc.beginEditBlock()
        # Do the actual work inside a try-finally block so as to be sure
        # that the Edit Block is ultimately closed.
        try :
            self.data_model.move_notes(worktc)
        except Exception as whatever:
            fnotview_logger.error(
                'Unexpected error moving footnotes: {}'.format(whatever.args)
                )
        worktc.endEditBlock()
        self.do_refresh()

    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    # Set-up functions for initializing the UI elements.

    # convenience functions to shorten the code of setting up 6 similar menus.
    # make a combobox loaded with the stream names and set to a particular one.
    def _make_cb(self, default, text) :
        cb = QComboBox()
        cb.addItems(stream_names)
        cb.setCurrentIndex(default)
        tt = _TR( 'Footnote panel popup menus',
                 'Choose the format to use when renumbering Note Keys such as:',
                 'will be followed by e.g. "[A]" or "[5]"' )
        cb.setToolTip(tt+text)
        return cb
    # combine a combobox with a label in an hbox
    def _make_pair(self, cb, caption):
        hb = QHBoxLayout()
        hb.addWidget( QLabel(caption) )
        hb.addWidget(cb)
        return hb

    def _uic(self):
        main_layout = QVBoxLayout()
        self.setLayout(main_layout)
        # make a horizontal layout of [Refresh       Renumber Move]
        top_box = QHBoxLayout()
        # make the Refresh button with translated text
        self.refresh_button = QPushButton(
            _TR('Footnote panel Refresh button', 'Refresh') )
        self.refresh_button.setToolTip(
            _TR('Footnote panel Refresh button',
                'Scan the book to find all footnotes and match them to their anchors' ) )
        top_box.addWidget(self.refresh_button,0)
        top_box.addStretch(1) # push next two buttons to the right
        # Make the Renumber button
        self.renumber_button = QPushButton(
            _TR('Footnote panel Renumber button', 'Renumber') )
        self.renumber_button.setToolTip(
            _TR('Footnote panel Renumber button',
                'Renumber all footnotes using the styles chosen in the menus below') )
        top_box.addWidget(self.renumber_button,0)
        # Make the Move button
        self.move_button = QPushButton(
            _TR('Footnote panel Move-to-zones button','Move to Zones') )
        self.move_button.setToolTip(
            _TR('Footnote panel Move button',
                'Move all footnotes into zones marked /F ... F/' ) )
        top_box.addWidget(self.move_button,0)
        # Put that row of buttons at the top of the panel
        main_layout.addLayout(top_box,0)
        # Create the table, a very basic one, no sorting etc.
        self.model = FnoteTableModel(self.data_model, self)
        self.view = QTableView()
        self.view.setModel(self.model)
        self.view.setCornerButtonEnabled(False)
        self.view.setWordWrap(False)
        self.view.setAlternatingRowColors(False)
        self.view.setSortingEnabled(False)
        main_layout.addWidget(self.view,1) # Table gets all the stretch
        # Create the six combo boxes. Initialize both IVX and ABC to
        # the ABC stream and ivx and abc to the abc.
        self.pick_IVX = self._make_cb(fnotdata.KeyClass_ABC, '[II]')
        self.pick_ABC = self._make_cb(fnotdata.KeyClass_ABC, '[B]' )
        self.pick_ivx = self._make_cb(fnotdata.KeyClass_abc, '[vi]')
        self.pick_abc = self._make_cb(fnotdata.KeyClass_abc, '[b]' )
        self.pick_123 = self._make_cb(fnotdata.KeyClass_123, '[2]' )
        self.pick_sym = self._make_cb(fnotdata.KeyClass_sym, '[§]' )
        # Create a 2x3 grid layout and put a label:combobox in each cell
        grid = QGridLayout()
        grid.addLayout( self._make_pair( self.pick_ABC, key_class_names[1] ), 0, 0)
        grid.addLayout( self._make_pair( self.pick_IVX, key_class_names[0] ), 1, 0)
        grid.addLayout( self._make_pair( self.pick_abc, key_class_names[3] ), 0, 1)
        grid.addLayout( self._make_pair( self.pick_ivx, key_class_names[2] ), 1, 1)
        grid.addLayout( self._make_pair( self.pick_123, key_class_names[4] ), 0, 2)
        grid.addLayout( self._make_pair( self.pick_sym, key_class_names[5] ), 1, 2)
        # Put the grid in an hbox with stretch on each side to center it
        gridhb = QHBoxLayout()
        gridhb.addStretch(1)
        gridhb.addLayout(grid,0)
        gridhb.addStretch(1)
        # Add that row to the main layout
        main_layout.addLayout(gridhb)
        # End of _uic
开发者ID:tallforasmurf,项目名称:PPQT2,代码行数:104,代码来源:fnotview.py

示例6: FilterableTable

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setAlternatingRowColors [as 别名]
class FilterableTable(SQLTable):
    """a filterable Table Widget that displays content of an SQLite table;
    for individual widgets, subclass 
     and overwrite the create_model method;
    add_color_proxy should be an (INT allele_status-column, INT lab_status-column) tuple
    """
    def __init__(self, log, mydb = ": memory :", add_color_proxy = False, header_dic = None):
        super().__init__(log, mydb)
        self.add_color_proxy = add_color_proxy
        self.header_dic = header_dic
        self.create_model()
        self.fill_UI()
        self.create_filter_model()
        self.update_filterbox()
        
    def fill_UI(self):
        """sets up the layout
        """
        self.log.debug("\t- Setting up the table...")
        self.table = QTableView()
        self.table.setContextMenuPolicy(Qt.CustomContextMenu)
        self.header = self.table.horizontalHeader() # table header
        self.header.setSectionResizeMode(QHeaderView.ResizeToContents)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setAlternatingRowColors(True)
#         self.header.sectionClicked.connect(self.on_header_sectionClicked)
        
        mode = QAbstractItemView.SingleSelection
        self.table.setSelectionMode(mode)
        
        self.grid.addWidget(self.table, 2, 0, 10, 10)

        self.filter_lbl = QLabel("Filter:", self)
        self.grid.addWidget(self.filter_lbl, 1, 2)
        
        self.filter_entry = QLineEdit(self)
        self.grid.addWidget(self.filter_entry, 1, 3)
        self.filter_entry.textChanged.connect(self.on_filter_entry_textChanged)
        self.filter_text = ""
        
        self.filter_cb = QComboBox(self)
        self.grid.addWidget(self.filter_cb, 1, 4)
        self.filter_cb.currentIndexChanged.connect(self.on_filter_cb_IndexChanged)
        
        self.filter_btn = QPushButton("Filter!", self)
        self.grid.addWidget(self.filter_btn, 1, 5)
        self.filter_btn.clicked.connect(self.on_filter_btn_clicked)
        
        self.unfilter_btn = QPushButton("Remove Filter", self)
        self.grid.addWidget(self.unfilter_btn, 1, 6)
        self.unfilter_btn.clicked.connect(self.on_actionAll_triggered)
        
        self.log.debug("\t=> Done!")
    
    def update_filterbox(self):
        """fills the filter-combobox with the header values 
        after the model has been created and set
        """
        column_num = self.model.columnCount()
        if self.header_dic:
            columns = [self.header_dic[i] for i in self.header_dic]
        else:
            columns = [self.proxy.headerData(i, Qt.Horizontal) for i in range(column_num)]
        self.filter_cb.addItems(columns)

    def create_filter_model(self):
        """creates the filter-proxy-model on top of self.model
        """
        self.log.debug("Creating filter model...")
        self.proxy = QSortFilterProxyModel(self)
        if self.add_color_proxy:
            (allele_status_column, lab_status_column) = self.add_color_proxy
            self.log.debug("adding color filter to columns {} and {}".format(allele_status_column, lab_status_column))
            self.color_proxy = ColorProxyModel(self, allele_status_column, lab_status_column)
            self.color_proxy.setSourceModel(self.model)
            self.proxy.setSourceModel(self.color_proxy)
        else:
            self.proxy.setSourceModel(self.model)
        self.table.setSortingEnabled(True)
        self.table.setModel(self.proxy)
        
    def on_filter_cb_IndexChanged(self, index):
        """restricts RegEx filter to selected column
        """
        self.log.debug("Combobox: colum {} selected".format(index))
        self.proxy.setFilterKeyColumn(index)
    
    def on_filter_entry_textChanged(self, text):
        """stores content of filter_entry as self.text 
        """
        self.log.debug("filter text: '{}'".format(text))
        self.filter_text = text
    
    def on_filter_btn_clicked(self):
        """activates RegEx filter to current content of filter_entry and filter_cb
        """
        column = self.filter_cb.currentIndex()
        self.log.debug("Filtering column {} for '{}'".format(column, self.filter_text))
        self.proxy.setFilterKeyColumn(column)
        search = QRegExp(self.filter_text, Qt.CaseInsensitive, QRegExp.RegExp)
#.........这里部分代码省略.........
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:103,代码来源:GUI_overviews.py


注:本文中的PyQt5.QtWidgets.QTableView.setAlternatingRowColors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。