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. Accessing qlabel created in designer from .h file.
Forum Updated to NodeBB v4.3 + New Features

Accessing qlabel created in designer from .h file.

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 674 Views
  • 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.
  • M Offline
    M Offline
    MyNameIsQt
    wrote on last edited by
    #1

    hello.
    I am new to qt.
    I created a QLabel with object name imageLabel in qt desinger. The imageLabel created in this way is displayed in the main window.
    How can we access this imageLabel in mainWindow.h?
    Please let me know how I can access it.
    And in vs++ it was possible to create a class object by making a static box into a picture box. Is it possible to create class object of imageLabel like this?

    jsulmJ 1 Reply Last reply
    0
    • M MyNameIsQt

      hello.
      I am new to qt.
      I created a QLabel with object name imageLabel in qt desinger. The imageLabel created in this way is displayed in the main window.
      How can we access this imageLabel in mainWindow.h?
      Please let me know how I can access it.
      And in vs++ it was possible to create a class object by making a static box into a picture box. Is it possible to create class object of imageLabel like this?

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

      @MyNameIsQt

      ui->imageLabel
      

      "And in vs++ it was possible to create a class object by making a static box into a picture box." - I don't understand this.

      "Is it possible to create class object of imageLabel like this?" - imageLabel IS already an object.

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

      M 1 Reply Last reply
      1
      • jsulmJ jsulm

        @MyNameIsQt

        ui->imageLabel
        

        "And in vs++ it was possible to create a class object by making a static box into a picture box." - I don't understand this.

        "Is it possible to create class object of imageLabel like this?" - imageLabel IS already an object.

        M Offline
        M Offline
        MyNameIsQt
        wrote on last edited by MyNameIsQt
        #3

        @jsulm
        Hi. thanks for your answer.
        I mean...
        In vc++, you can attach a static box when configuring a form design in a .rc file.
        Set the id of this static as idc_picture. then

        CPictureBox *m_picturebox=((CPictureBox *)m_nMainDlg->GetDlgItem(IDC_PICTUREBOX));
        

        We can create a class like this.

        class CPictureBox : public CStatic
        
        
        jsulmJ Christian EhrlicherC 2 Replies Last reply
        0
        • M MyNameIsQt

          @jsulm
          Hi. thanks for your answer.
          I mean...
          In vc++, you can attach a static box when configuring a form design in a .rc file.
          Set the id of this static as idc_picture. then

          CPictureBox *m_picturebox=((CPictureBox *)m_nMainDlg->GetDlgItem(IDC_PICTUREBOX));
          

          We can create a class like this.

          class CPictureBox : public CStatic
          
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @MyNameIsQt I still don't understand what you're trying to achieve. Can you describe it better?

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

          M 1 Reply Last reply
          0
          • M MyNameIsQt

            @jsulm
            Hi. thanks for your answer.
            I mean...
            In vc++, you can attach a static box when configuring a form design in a .rc file.
            Set the id of this static as idc_picture. then

            CPictureBox *m_picturebox=((CPictureBox *)m_nMainDlg->GetDlgItem(IDC_PICTUREBOX));
            

            We can create a class like this.

            class CPictureBox : public CStatic
            
            
            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • jsulmJ jsulm

              @MyNameIsQt I still don't understand what you're trying to achieve. Can you describe it better?

              M Offline
              M Offline
              MyNameIsQt
              wrote on last edited by
              #6

              @jsulm
              I'm trying to load an image and draw it on a label. I want this label to be a class without being tied to a member variable.
              In vc++, it was possible to include onPaint() event in picturebox(CStatic).
              So I wanted to know how I could make something similar by making the object of qlabel a class.

              jsulmJ 1 Reply Last reply
              0
              • M MyNameIsQt

                @jsulm
                I'm trying to load an image and draw it on a label. I want this label to be a class without being tied to a member variable.
                In vc++, it was possible to include onPaint() event in picturebox(CStatic).
                So I wanted to know how I could make something similar by making the object of qlabel a class.

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

                @MyNameIsQt said in Accessing qlabel created in designer from .h file.:

                I want this label to be a class without being tied to a member variable
                by making the object of qlabel a class

                Sorry, I'm confused now. A class is NOT an object, an object is an instance of a class.

                I think what you're actually asking is this: you want to subclass QLabel to create your own class based on QLabel, right?
                But before we continue: do you really need to draw the picture manually? There are https://doc.qt.io/qt-6/qlabel.html#setPicture and https://doc.qt.io/qt-6/qlabel.html#pixmap-prop to set a picture on a label.

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

                M 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @MyNameIsQt said in Accessing qlabel created in designer from .h file.:

                  I want this label to be a class without being tied to a member variable
                  by making the object of qlabel a class

                  Sorry, I'm confused now. A class is NOT an object, an object is an instance of a class.

                  I think what you're actually asking is this: you want to subclass QLabel to create your own class based on QLabel, right?
                  But before we continue: do you really need to draw the picture manually? There are https://doc.qt.io/qt-6/qlabel.html#setPicture and https://doc.qt.io/qt-6/qlabel.html#pixmap-prop to set a picture on a label.

                  M Offline
                  M Offline
                  MyNameIsQt
                  wrote on last edited by
                  #8

                  @jsulm
                  Oh. You right. That's i'm trying to do now.
                  thanks a lot.

                  1 Reply Last reply
                  0
                  • M MyNameIsQt has marked this topic as solved on

                  • Login

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