Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dropdown menu for 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
Comment

PREVIOUS NEXT
Code Example
Python :: how to recurse a function 
Python :: apolatrix 
Python :: pandas et numeric columns 
Python :: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead. 
Python :: anaconda create new environment 
Python :: python index where true 
Python :: python timestamp shift one day 
Python :: python calling dynamic function on object 
Python :: add footer embed discordpy 
Python :: python elementtree build xml 
Python :: Python program that takes 2 words as input from the user and prints out a list containing the letters that the 2 words have in common 
Python :: train test split pandas 
Python :: print the heat map python 
Python :: changes not showing on website server odoo 
Python :: sigmoid in python from scratch 
Python :: Fill NaN of a column with values from another column 
Python :: import py to exe 
Python :: streamlit st.file_uploader 
Python :: pandas dataframe aggregations 
Python :: How to to efficiently find the first index in a sorted array of distinct numbers that is equal to the value at that index? 
Python :: how to get total number of rows in listbox tkinter 
Python :: install python 3.6 ubuntu 16.04 
Python :: save ml model using joblib 
Python :: select only object columns pandas 
Python :: streamlit button to load a file 
Python :: python search for string in file 
Python :: check if numpy array is 1d 
Python :: txt file duplicate line remover python 
Python :: what is actually better duracell or energizer 
Python :: django email settings 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =