Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to enter Images in a listWidget inside tabWidget
Forum Updated to NodeBB v4.3 + New Features

How to enter Images in a listWidget inside tabWidget

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 6 Posters 5.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Osama_Billah

    @jsulm @anil_arise @SGaist oky thank you I'm checking that. as I'm new so It allow me to post after 10 min so sorry for late reply. and another question as I name the tab like tab1, tab2 so how can I call it. because it gave an error " 'QWidget' object has no attribute 'clicked' "

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #14

    @Osama_Billah said in How to enter Images in a listWidget inside tabWidget:

    because it gave an error " 'QWidget' object has no attribute 'clicked' "

    It's not clear to me what you're trying to achieve. If you want to get a signal if a tab was activated then use https://doc.qt.io/qt-5/qtabwidget.html#currentChanged

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    O 1 Reply Last reply
    1
    • jsulmJ jsulm

      @Osama_Billah said in How to enter Images in a listWidget inside tabWidget:

      because it gave an error " 'QWidget' object has no attribute 'clicked' "

      It's not clear to me what you're trying to achieve. If you want to get a signal if a tab was activated then use https://doc.qt.io/qt-5/qtabwidget.html#currentChanged

      O Offline
      O Offline
      Osama_Billah
      wrote on last edited by
      #15

      @jsulm I wanna to do this

      self.tab_2.clicked.connect(self.images_for_tab2)
      

      if the user click on tab_2 it call the own function.
      @anil_arise as I write the code it gave an error on invalid syntax. I'm Using python.
      Sorry for the trouble but I'm new learner.

      jsulmJ 1 Reply Last reply
      0
      • O Osama_Billah

        @jsulm I wanna to do this

        self.tab_2.clicked.connect(self.images_for_tab2)
        

        if the user click on tab_2 it call the own function.
        @anil_arise as I write the code it gave an error on invalid syntax. I'm Using python.
        Sorry for the trouble but I'm new learner.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #16

        @Osama_Billah https://doc.qt.io/qt-5/qtabwidget.html#currentChanged
        If you get errors please post your code and errors.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • O Offline
          O Offline
          Osama_Billah
          wrote on last edited by
          #17
           self.tab.clicked.connect(self.images_for_tab1)
          
                  self.retranslateUi(MainWindow)
                  self.tabWidget.setCurrentIndex(2)
                  QtCore.QMetaObject.connectSlotsByName(MainWindow)
          
          
          
              def images_for_tab1(self):
                  #images in the list will come from a webURL
          
                  QListWidget * listwidget = new QListWidget()
                  #ui->tabWidget->addTab(listwidget,QIcon(":/img/alert.png"),"NewTab");
          
                  QListWidgetItem *item1 = new QListWidgetItem(QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG"),"item1")
                  listwidget->addItem(item1)
                  QListWidgetItem *item2 = new QListWidgetItem(QIcon("C:/Users/OB/Desktop/DevoMech Project/5.JPG" , "item2")
                  listwidget->addItem(item2)
          

          Capture.PNG

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Osama_Billah
            wrote on last edited by
            #18

            @jsulm @SGaist @anil_arise @JonB Thanks for your time. I know it's hard for all of you but I'm totally new and have no idea.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #19

              You are mixing C++ syntax with Python syntax, that's the error you are getting. There's not pointer nor new operator in Python.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              O 1 Reply Last reply
              1
              • SGaistS SGaist

                You are mixing C++ syntax with Python syntax, that's the error you are getting. There's not pointer nor new operator in Python.

                O Offline
                O Offline
                Osama_Billah
                wrote on last edited by
                #20

                @SGaist I change it to this

                        self.item1 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG", "item1")
                        self.listWidget_3.addItem(item1)
                        self.item2 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/5.JPG", "item2")
                        self.listWidget_3.addItem(item2)
                

                Now the error is
                Traceback (most recent call last):
                File "C:\Users\OB\Desktop\DevoMech Project\test_for_de.py", line 127, in <module>
                ui.setupUi(MainWindow)
                File "C:\Users\OB\Desktop\DevoMech Project\test_for_de.py", line 83, in setupUi
                self.item1 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG", "item1")
                AttributeError: 'Ui_MainWindow' object has no attribute 'QListWidgetItem'

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  Osama_Billah
                  wrote on last edited by
                  #21

                  problem solved. thanks @SGaist @jsulm @anil_arise @JonB I just want to know that every beginner face these problems. or I'm the special one.

                  jsulmJ 1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    Osama_Billah
                    wrote on last edited by
                    #22
                            item1 = QtWidgets.QListWidgetItem(QIcon("path_to_pic"), "Name_of_pic")
                            self.listWidget_2.addItem(item1)
                            item2 = QtWidgets.QListWidgetItem(QIcon("path_to_pic"), "Name_of_pic!
                            self.listWidget_2.addItem(item2)
                    

                    Capture.PNG

                    1 Reply Last reply
                    1
                    • O Osama_Billah

                      problem solved. thanks @SGaist @jsulm @anil_arise @JonB I just want to know that every beginner face these problems. or I'm the special one.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #23

                      @Osama_Billah said in How to enter Images in a listWidget inside tabWidget:

                      I just want to know that every beginner face these problems. or I'm the special one.

                      At the beginning we are all beginners :-)

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      JonBJ 1 Reply Last reply
                      1
                      • J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #24

                        Off topic replies forked to here:

                        https://forum.qt.io/topic/111424/the-art-of-programming


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        3
                        • O Offline
                          O Offline
                          Osama_Billah
                          wrote on last edited by
                          #25

                          Thanks for your response. One more thing how to convert these images horizontally and increase the size. @SGaist @jsulm @anil_arise @JonB

                          1 Reply Last reply
                          0
                          • O Offline
                            O Offline
                            Osama_Billah
                            wrote on last edited by Osama_Billah
                            #26

                            this is the code. I used QIcon the one @anil_arise suggest

                            self.tabWidget.setIconSize(QtCore.QSize(32, 32))
                            QtWidgets.QListWidgetItem.setLayoutDirection(QtCore.Qt.LeftToRight)
                            
                            
                            
                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved