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


Python QTableView.horizontalHeader方法代码示例

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


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

示例1: main

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
def main(args):
    app = QApplication(args)
    page = QSplitter()
    data = Model(1000, 10, page)
    selections = QItemSelectionModel(data)
    table = QTableView()
    table.setModel(data)
    table.setSelectionModel(selections)
    table.horizontalHeader().setSectionsMovable(True)
    table.verticalHeader().setSectionsMovable(True)
    # Set StaticContents to enable minimal repaints on resizes.
    table.viewport().setAttribute(Qt.WA_StaticContents)
    page.addWidget(table)
    tree = QTreeView()
    tree.setModel(data)
    tree.setSelectionModel(selections)
    tree.setUniformRowHeights(True)
    tree.header().setStretchLastSection(False)
    tree.viewport().setAttribute(Qt.WA_StaticContents)
    # Disable the focus rect to get minimal repaints when scrolling on Mac.
    tree.setAttribute(Qt.WA_MacShowFocusRect, False)
    page.addWidget(tree)
    list = QListView()
    list.setModel(data)
    list.setSelectionModel(selections)
    list.setViewMode(QListView.IconMode)
    list.setSelectionMode(QAbstractItemView.ExtendedSelection)
    list.setAlternatingRowColors(False)
    list.viewport().setAttribute(Qt.WA_StaticContents)
    list.setAttribute(Qt.WA_MacShowFocusRect, False)
    page.addWidget(list)
    page.setWindowIcon(QIcon(images_dir + '/interview.png'))
    page.setWindowTitle("Interview")
    page.show()
    return app.exec_()
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:37,代码来源:interview.py

示例2: GroupWidget

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

    _COLUMN_MAP = students.StudentColumnMap(
        columns=[
            students.StudentColumn.SEQUENCE_NUM,
            students.StudentColumn.ID,
            students.StudentColumn.NAME,
        ])

    def __init__(self, listing, student_tabs):
        super().__init__(student_tabs.tabs)
        self.listing = listing
        layout = QVBoxLayout()
        self.setLayout(layout)
        self.table = QTableView()
        self.table.setMinimumWidth(500)
        self.table.setMinimumHeight(300)
        layout.addWidget(self.table)
        self.model = StudentsTableModel(listing, GroupWidget._COLUMN_MAP, self)
        self.table.setModel(self.model)
        self.table.setSelectionBehavior(QTableView.SelectRows)
        layout.setAlignment(self.table, Qt.AlignHCenter)
        self._resize_table()

    def add_students(self, student_list):
        self.listing.add_students(student_list)
        self.listing_updated()

    def listing_updated(self):
        self.model.data_reset()
        self._resize_table()

    def _resize_table(self):
        self.table.resizeColumnToContents(0)
        self.table.horizontalHeader().setStretchLastSection(True)
开发者ID:jfisteus,项目名称:eyegrade,代码行数:37,代码来源:students.py

示例3: _makeTable

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
    def _makeTable(self, model):
        table = QTableView(self)
        table.setModel(model)
        table.hideColumn(0)
        table.setShowGrid(False)

        subListDelegate = SubListItemDelegate()
        table.setItemDelegateForColumn(1, subListDelegate)
        table.setItemDelegateForColumn(2, subListDelegate)
        table.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
        table.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
        return table
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:Synchronizer.py

示例4: SetupUI

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
    def SetupUI(self, w):
        info("SetupUI")

        # Search bar
        lblName = QLabel('Search')
        lblResults = QLabel('Results')

        # Plugin table
        ledtName = QLineEdit()
        tblResults = QTableView()
        tblResultsModel = PluginTableModel(self.available_plugins, Plugin.SQLITE_COLUMNS, w)
        tblResults.setModel( tblResultsModel )
        tblResults.horizontalHeader().setStretchLastSection(True)
        tblResults.verticalHeader().setVisible(False)
        tblResults.resizeColumnsToContents()
        tblResults.setSortingEnabled(True)
        tblResults.setFont( QFont("Courier New", 8) )
        tblResults.setShowGrid(False)

        ## event handlers
        ledtName.textChanged.connect(self.OnSearchFieldChange)


        # Button row
        btnUpdate = QPushButton("Refresh Plugins List")
        btnInstall = QPushButton("Install")

        ## event handlers
        btnUpdate.clicked.connect(self.RefreshPluginsList)
        btnInstall.clicked.connect(self.InstallSelected)


        grid = QGridLayout()
        grid.addWidget(lblName, 1, 0)
        grid.addWidget(ledtName, 1, 1)
        grid.addWidget(lblResults, 2, 0)
        grid.addWidget(tblResults, 2, 1, 5, 1)

        vbox = QVBoxLayout()
        vbox.addStretch(1)
        vbox.addWidget(btnUpdate)
        vbox.addWidget(btnInstall)
        wButtons = QWidget()
        wButtons.setLayout(vbox)

        grid.addWidget(wButtons, 5, 1, 4, 1)
        w.setLayout(grid)
        return
开发者ID:hugsy,项目名称:stuff,代码行数:50,代码来源:IdaPluginManager.py

示例5: UdpLogReceiver

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class UdpLogReceiver(QWidget):
    """
        Log events generated by python logging objects.
    """
    def __init__(self, parent=None):
        super().__init__(parent)
        self._model = LogRecordModel()
        filter_model = QSortFilterProxyModel()
        filter_model.setSourceModel(self._model)
        filter_model.setFilterKeyColumn(3)

        self.msg_filter = QLineEdit()
        self.log_view = QTableView()
        self.log_view.setModel(filter_model)
        header = self.log_view.horizontalHeader()
        #header.setSectionResizeMode(header.Stretch)
        header.setStretchLastSection(True)
        self.status_label = QLabel()

        # Connect signals:
        self.msg_filter.textChanged.connect(filter_model.setFilterFixedString)
        # Make nice layout:
        layout = QVBoxLayout(self)
        layout.addWidget(self.msg_filter)
        layout.addWidget(self.log_view)
        layout.addWidget(self.status_label)

        # Attach udp server:
        self._udpServer = UdpHandler(self._model)
        self._model.stats_changed.connect(self.status_label.setText)
开发者ID:windelbouwman,项目名称:udplogviewer,代码行数:32,代码来源:udplogreceiver.py

示例6: ProblemDialog

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class ProblemDialog(QDialog):
    def __init__(self, parent, model, **kwargs):
        flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
        super().__init__(parent, flags, **kwargs)
        self._setupUi()
        self.model = model
        self.model.view = self
        self.table = ProblemTable(self.model.problem_table, view=self.tableView)

        self.revealButton.clicked.connect(self.model.reveal_selected_dupe)
        self.closeButton.clicked.connect(self.accept)

    def _setupUi(self):
        self.setWindowTitle(tr("Problems!"))
        self.resize(413, 323)
        self.verticalLayout = QVBoxLayout(self)
        self.label = QLabel(self)
        msg = tr(
            "There were problems processing some (or all) of the files. The cause of "
            "these problems are described in the table below. Those files were not "
            "removed from your results."
        )
        self.label.setText(msg)
        self.label.setWordWrap(True)
        self.verticalLayout.addWidget(self.label)
        self.tableView = QTableView(self)
        self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
        self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableView.setShowGrid(False)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.verticalHeader().setDefaultSectionSize(18)
        self.tableView.verticalHeader().setHighlightSections(False)
        self.verticalLayout.addWidget(self.tableView)
        self.horizontalLayout = QHBoxLayout()
        self.revealButton = QPushButton(self)
        self.revealButton.setText(tr("Reveal Selected"))
        self.horizontalLayout.addWidget(self.revealButton)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.closeButton = QPushButton(self)
        self.closeButton.setText(tr("Close"))
        self.closeButton.setDefault(True)
        self.horizontalLayout.addWidget(self.closeButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
开发者ID:atiarda,项目名称:dupeguru,代码行数:47,代码来源:problem_dialog.py

示例7: setupViews

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
    def setupViews(self):
        splitter = QSplitter()
        table = QTableView()
        self.pieChart = PieView()
        splitter.addWidget(table)
        splitter.addWidget(self.pieChart)
        splitter.setStretchFactor(0, 0)
        splitter.setStretchFactor(1, 1)

        table.setModel(self.model)
        self.pieChart.setModel(self.model)

        self.selectionModel = QItemSelectionModel(self.model)
        table.setSelectionModel(self.selectionModel)
        self.pieChart.setSelectionModel(self.selectionModel)

        table.horizontalHeader().setStretchLastSection(True)

        self.setCentralWidget(splitter)
开发者ID:PWilsonUofC,项目名称:VGenes,代码行数:21,代码来源:chart.py

示例8: draw_table

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
 def draw_table():
     tv = QTableView()
     tv.setMinimumSize(400, 400)
     tv.setShowGrid(False)
     vh = tv.verticalHeader()
     vh.setVisible(False)
     hh = tv.horizontalHeader()
     hh.setStretchLastSection(True)
     tv.setSortingEnabled(True)
     return tv
开发者ID:bohdanbobrowski,项目名称:keyword-counter,代码行数:12,代码来源:keyword_counter_window.py

示例9: PreviewWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class PreviewWidget(QWidget):
    def __init__(self, student_list, column_map, parent=None):
        super().__init__(parent)
        self.listing = students.GroupListing(None, student_list)
        self.column_map = column_map
        layout = QVBoxLayout()
        self.setLayout(layout)
        self.table = QTableView()
        self.table.setMinimumWidth(600)
        self.table.setMinimumHeight(300)
        layout.addWidget(self.table)
        self.model = StudentsTableModel(self.listing, column_map, self)
        self.table.setModel(self.model)
        self.table.setSelectionMode(QTableView.NoSelection)
        layout.setAlignment(self.table, Qt.AlignHCenter)
        self._resize_table()

    def swap_names(self):
        for s in self.listing.students:
            s.first_name, s.last_name = s.last_name, s.first_name
        self.model.data_reset()
        self._resize_table()

    def to_full_name(self, column):
        attr_name = students.ATTR_NAME[column]
        for s in self.listing.students:
            s.full_name = getattr(s, attr_name)
            s.first_name = ''
            s.last_name = ''
        self.column_map = self.column_map.to_full_name()
        self.model.data_reset(column_map=self.column_map)
        self._resize_table()

    def remove_duplicates(self):
        self.listing.remove_students([s for s in self.listing.students
                                      if s.is_duplicate])
        self.model.data_reset()

    def _resize_table(self):
        for i in range(len(self.column_map) - 1):
            self.table.resizeColumnToContents(i)
        self.table.horizontalHeader().setStretchLastSection(True)
开发者ID:jfisteus,项目名称:eyegrade,代码行数:44,代码来源:students.py

示例10: createLibraryPlaylisView

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
    def createLibraryPlaylisView(self, uuid):
        playlistModel = PlaylistModel(uuid)

        playlistView = QTableView(self)
        playlistView.setModel(playlistModel)
        playlistView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        playlistView.setSortingEnabled(True)
        playlistView.setSelectionBehavior(QAbstractItemView.SelectRows)
        playlistView.setShowGrid(False)
        playlistView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)

        playlistView.doubleClicked.connect(self._doubleCLickedWidget)
        playlistView.customContextMenuRequested.connect(
            self.customMenuRequested)

        self.playlistMappings[uuid] = playlistView
        self.insertWidget(0, playlistView)
        self.setCurrentWidget(self.playlistMappings[uuid])
开发者ID:gdankov,项目名称:sonance-music-player,代码行数:22,代码来源:widgets.py

示例11: IgnoreListDialog

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class IgnoreListDialog(QDialog):
    def __init__(self, parent, model, **kwargs):
        flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
        super().__init__(parent, flags, **kwargs)
        self._setupUi()
        self.model = model
        self.model.view = self
        self.table = IgnoreListTable(self.model.ignore_list_table, view=self.tableView)

        self.removeSelectedButton.clicked.connect(self.model.remove_selected)
        self.clearButton.clicked.connect(self.model.clear)
        self.closeButton.clicked.connect(self.accept)

    def _setupUi(self):
        self.setWindowTitle(tr("Ignore List"))
        self.resize(540, 330)
        self.verticalLayout = QVBoxLayout(self)
        self.tableView = QTableView()
        self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableView.setShowGrid(False)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.verticalHeader().setDefaultSectionSize(18)
        self.tableView.verticalHeader().setHighlightSections(False)
        self.tableView.verticalHeader().setVisible(False)
        self.verticalLayout.addWidget(self.tableView)
        self.removeSelectedButton = QPushButton(tr("Remove Selected"))
        self.clearButton = QPushButton(tr("Clear"))
        self.closeButton = QPushButton(tr("Close"))
        self.verticalLayout.addLayout(
            horizontalWrap([
                self.removeSelectedButton, self.clearButton,
                None, self.closeButton
            ])
        )

    #--- model --> view
    def show(self):
        super().show()
开发者ID:1kakarot,项目名称:dupeguru,代码行数:42,代码来源:ignore_list_dialog.py

示例12: InvertedTable

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [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

示例13: SubtitleEditor

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class SubtitleEditor(SubTab):
    def __init__(self, filePath, subtitleData, parent = None):
        name = os.path.split(filePath)[1]
        super(SubtitleEditor, self).__init__(name, parent)
        self.__initWidgets()
        self.__initContextMenu()

        self._settings = SubSettings()

        self._filePath = filePath
        self._movieFilePath = None
        self._subtitleData = subtitleData

        self.refreshSubtitles()

        # Some signals
        self._subtitleData.fileChanged.connect(self.fileChanged)
        self._subtitleData.subtitlesAdded.connect(self._subtitlesAdded)
        self._subtitleData.subtitlesRemoved.connect(self._subtitlesRemoved)
        self._subtitleData.subtitlesChanged.connect(self._subtitlesChanged)
        self._model.itemChanged.connect(self._subtitleEdited)
        self.customContextMenuRequested.connect(self.showContextMenu)

    def __initWidgets(self):
        minimalSizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        # List of subtitles
        subListDelegate = SubListItemDelegate()
        self._model = QStandardItemModel(0, 3, self)
        self._model.setHorizontalHeaderLabels([_("Begin"), _("End"), _("Subtitle")])
        self._subList = QTableView(self)
        self._subList.setModel(self._model)
        self._subList.setItemDelegateForColumn(0, subListDelegate)
        self._subList.setItemDelegateForColumn(1, subListDelegate)
        self._subList.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)

        self._searchBar = SearchBar(self)
        self._searchBar.hide()

        # Top toolbar
        toolbar = QHBoxLayout()
        toolbar.setAlignment(Qt.AlignLeft)
        #toolbar.addWidget(someWidget....)
        toolbar.addStretch(1)

        # Main layout
        grid = QGridLayout()
        grid.setSpacing(10)
        grid.setContentsMargins(0, 3, 0, 0)
        grid.addLayout(toolbar, 0, 0, 1, 1) # stretch to the right
        grid.addWidget(self._subList, 1, 0)
        grid.addWidget(self._searchBar, 2, 0)
        self.setLayout(grid)

    def __initContextMenu(self):
        self._contextMenu = QMenu(self)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        af = ActionFactory(self)

        insertSub = af.create(title = _("&Insert subtitle"), icon = "list-add",
            connection = self.insertNewSubtitle)
        self._contextMenu.addAction(insertSub)

        insertSub = af.create(title = _("&Add subtitle"), icon = "list-add",
            connection = self.addNewSubtitle)
        self._contextMenu.addAction(insertSub)

        removeSub = af.create(title = _("&Remove subtitles"), icon = "list-remove",
            connection = self.removeSelectedSubtitles)
        self._contextMenu.addAction(removeSub)

    def _changeRowBackground(self, rowNo, bg):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            for columnNo in range(self._model.columnCount()):
                item = self._model.item(rowNo, columnNo)
                item.setBackground(bg)

    def _changeItemData(self, item, val, role):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            item.setData(val, role)

    def _handleIncorrectItem(self, item):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            item.setData(False, CustomDataRoles.ErrorFlagRole)

        bg = item.background()
        rowNo = item.row()
        self._changeRowBackground(rowNo, Qt.red)
        QTimer.singleShot(600, lambda rowNo=rowNo, bg=bg: self._changeRowBackground(rowNo, bg))

    def _subtitleEdited(self, item):
        modelIndex = item.index()
        column = modelIndex.column()
        subNo = modelIndex.row()

        errorFlag = item.data(CustomDataRoles.ErrorFlagRole)
        if errorFlag is True:
            self._handleIncorrectItem(item)
        else:
            # TODO: timeStart and timeEnd might be displayed in a frame format in a bright future.
#.........这里部分代码省略.........
开发者ID:mgoral,项目名称:subconvert,代码行数:103,代码来源:SubtitleTabs.py

示例14: MainWindow

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

#.........这里部分代码省略.........
        self.model2.setHeaderData(1, Qt.Horizontal, "개수")


    def setupViews(self):
        splitter = QSplitter()
        self.table = QTableView()
        self.pieChart = PieView()


        splitter.addWidget(self.pieChart)
        splitter.addWidget(self.table)
        splitter.setStretchFactor(0, 0)
        splitter.setStretchFactor(1, 0)

        self.table.setModel(self.model)
        self.pieChart.setModel(self.model2)

        self.selectionModel = QItemSelectionModel(self.model2)
        self.table.setSelectionModel(self.selectionModel)

        #self.pieChart.setSelectionModel(self.selectionModel)

        #table.setColumnWidth(0,100)
        self.setCentralWidget(splitter)
        self.table.doubleClicked.connect(self.ClickAction_table)

    def readDB(self):

        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("select subject, readcheck from study;")
        self.model.removeRows(0, self.model.rowCount(QModelIndex()),
                        QModelIndex())
        self.model2.removeRows(0, self.model2.rowCount(QModelIndex()),
                        QModelIndex())
        row = 0
        for line in cur:
            if line[1] ==1:
                result = "○"
            else:
                result = "X"
            self.model.insertRows(row, 1, QModelIndex())
            self.model.setData(self.model.index(row, 0, QModelIndex()), line[0])
            self.model.setData(self.model.index(row, 1, QModelIndex()),result)
            self.model.setData(self.model.index(row, 1, QModelIndex()), QVariant(Qt.AlignCenter),Qt.TextAlignmentRole)
            row += 1
        cur.execute("select count() from study ;")
        for line in cur:
            self.studyTotal =line[0]
        cur.execute("select count() from study where readcheck=1;")
        for line in cur:
            self.studyRead =line[0]
        #print("총 개수 " ,self.studyTotal ," 학습한개수", self.studyRead )
        con.close()
        row=0
        self.model2.insertRows(row, 1, QModelIndex())
        self.model2.setData(self.model2.index(row, 0, QModelIndex()),"학습")
        self.model2.setData(self.model2.index(row, 1, QModelIndex()), float(self.studyRead))
        self.model2.setData(self.model2.index(row, 0, QModelIndex()), QColor("#99e600"), Qt.DecorationRole)
        row=1
        self.model2.insertRows(row, 1, QModelIndex())
        self.model2.setData(self.model2.index(row, 0, QModelIndex()),"미학습")
        self.model2.setData(self.model2.index(row, 1, QModelIndex()), float(self.studyTotal-self.studyRead))
        self.model2.setData(self.model2.index(row, 0, QModelIndex()), QColor("#8080b3"), Qt.DecorationRole)


        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setSelectionMode(QAbstractItemView.SingleSelection)
        self.table.setDragEnabled(False)
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.resizeRowsToContents()
        self.table.resizeColumnsToContents()
        self.table.setColumnWidth(0,350)
                    #self.statusBar().showMessage("Loaded %s" % path, 2000)
    def ClickAction_table(self,index):
        #self.system
        #index.data()
        #self.table.selectedIndexes()[0].data()
        tempstr = self.table.selectedIndexes()[0].data().split()
        filepath = r"PyStudy_web\\example\\기본예제\\"+tempstr[0]+".html"
        selectedRowKey = self.table.selectedIndexes()[0].row()+1#mysql 테이블 줄수 차이
        #print("click test ",selectedRowKey )
        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("update 'study' set 'readcheck'=1 where key="+str(selectedRowKey)+";")
        con.commit()
        con.close()
        self.setupViews()
        self.readDB()

        self.system.sendMessage("/학습창 열기 "+filepath)
    def ClickAction_dbinit(self,index):
        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("update 'study' set 'readcheck'=0 ;")
        con.commit()
        con.close()
        self.setupViews()
        self.readDB()
开发者ID:louisraccoon,项目名称:PyStudy,代码行数:104,代码来源:StudyPlan.py

示例15: FreezeTableWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import horizontalHeader [as 别名]
class FreezeTableWidget(QTableView):
    def __init__(self, model):
        super(FreezeTableWidget, self).__init__()
        self.setModel(model)
        self.frozenTableView = QTableView(self)
        self.init()
        self.horizontalHeader().sectionResized.connect(self.updateSectionWidth)
        self.verticalHeader().sectionResized.connect(self.updateSectionHeight)
        self.frozenTableView.verticalScrollBar().valueChanged.connect(
            self.verticalScrollBar().setValue)
        self.verticalScrollBar().valueChanged.connect(
            self.frozenTableView.verticalScrollBar().setValue)

    def init(self):
        self.frozenTableView.setModel(self.model())
        self.frozenTableView.setFocusPolicy(Qt.NoFocus)
        self.frozenTableView.verticalHeader().hide()
        self.frozenTableView.horizontalHeader().setSectionResizeMode(
                QHeaderView.Fixed)
        self.viewport().stackUnder(self.frozenTableView)

        self.frozenTableView.setStyleSheet('''
            QTableView { border: none;
                         background-color: #8EDE21;
                         selection-background-color: #999;
            }''') # for demo purposes

        self.frozenTableView.setSelectionModel(self.selectionModel())
        for col in range(1, self.model().columnCount()):
            self.frozenTableView.setColumnHidden(col, True)
        self.frozenTableView.setColumnWidth(0, self.columnWidth(0))
        self.frozenTableView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.frozenTableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.frozenTableView.show()
        self.updateFrozenTableGeometry()
        self.setHorizontalScrollMode(self.ScrollPerPixel)
        self.setVerticalScrollMode(self.ScrollPerPixel)
        self.frozenTableView.setVerticalScrollMode(self.ScrollPerPixel)

    def updateSectionWidth(self, logicalIndex, oldSize, newSize):
        if self.logicalIndex == 0:
            self.frozenTableView.setColumnWidth(0, newSize)
            self.updateFrozenTableGeometry()

    def updateSectionHeight(self, logicalIndex, oldSize, newSize):
        self.frozenTableView.setRowHeight(logicalIndex, newSize)

    def resizeEvent(self, event):
        super(FreezeTableWidget, self).resizeEvent(event)
        self.updateFrozenTableGeometry()

    def moveCursor(self, cursorAction, modifiers):
        current = super(FreezeTableWidget, self).moveCursor(cursorAction, modifiers)
        if (cursorAction == self.MoveLeft and
                self.current.column() > 0 and
                self.visualRect(current).topLeft().x() <
                    self.frozenTableView.columnWidth(0)):
            newValue = (self.horizontalScrollBar().value() +
                        self.visualRect(current).topLeft().x() -
                        self.frozenTableView.columnWidth(0))
            self.horizontalScrollBar().setValue(newValue)
        return current

    def scrollTo(self, index, hint):
        if index.column() > 0:
            super(FreezeTableWidget, self).scrollTo(index, hint)

    def updateFrozenTableGeometry(self):
        self.frozenTableView.setGeometry(
                self.verticalHeader().width() + self.frameWidth(),
                self.frameWidth(), self.columnWidth(0),
                self.viewport().height() + self.horizontalHeader().height())
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:74,代码来源:frozencolumn.py


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