2

I have a program that include QTabWidget with 2 tabs.

what I need is to check if the second Tab is active or has focus run a function.

I tried this code until now but did not work


def checkTab2(self):
    if self.tabWidget.currentIndex()==1:
        print("index 2 ")

def checkTab2(self):
    if self.tab_2.hasFocus():
        print("index 2 ")

def checkTab2(self):
    if self.tab_2.isActiveWindow():
        print("index 2 ")

all these three did not work.

based on answer i am able to check which is the current tab.

but now i am not able to do anything in the second tab unless i changed to the first and go back to the second.

like here i am trying to display result from the list in the second tab

    def checkTab2(self):
        if self.tab_2 == self.tabWidget.currentWidget():            
            if len(self.listWidget_reportNames)>0:               
                self.displayReport(self.reportSeleted())


    def reportSeleted(self):
        curItem = self.listWidget_reportNames.currentItem().text()
        #print("this is te curItem {}".format(curItem))

        return curItem

    def displayReport(self,item):
        searchRes=os.path.join(os.getcwd(),"search_result")
        path = os.listdir(searchRes)
        try:
            for file in path:            
                rpjson = json.load(open(os.path.join(searchRes,item)))
                for js in rpjson:
                    self.textEdit.setHtml("File name {}\n".format(js["File Name"] +
                                                                "Searched Word {}\n".format(js["Searched Word"] + 
                                                                                          "Number Of Occurence {}".format(js["Number Of Occurence"] ))))
        except Exception as e:
            print("can't read JSON because {}".format(e))

can anyone help me with this?

Propy Propy
  • 57
  • 10

0 Answers0