Rozwijane menu dla qheaderview python

Przykłady kodu

1
0

rozwijane menu dla qheaderview python

  self.tableView.horizontalHeader().sectionClicked.connect(self.headerClicked) 
  
  def headerClicked(self, index):
        self.columnIndex = index
        menu = QMenu(self)
        menuItems = list(dict.fromkeys(df.iloc[:, index].tolist())) # list from selected column and drop duplicates
        for item in menuItems:
            action = QAction(str(item), self)	# str(item) - init action title
            action.setData(item)		# init action value
            action.triggered.connect(self.itemClicked)
            menu.addAction(action)
        headerPos = self.tableView.mapToGlobal(self.tableView.horizontalHeader().pos())
        posY = headerPos.y() + self.tableView.horizontalHeader().height()
        posX = headerPos.x() + self.tableView.horizontalHeader().sectionViewportPosition(index)
        menu.exec_(QPoint(posX, posY))

    def itemClicked(self):
    	action = self.sender()
        print("Filtering column {}".format(self.columnIndex), action.data())
        # implement your need

Podobne strony

Podobne strony do przykłady

W innych językach

Ta strona jest w innych językach

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................