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 draw QLineEdit over top of QLabel?
Forum Updated to NodeBB v4.3 + New Features

How to draw QLineEdit over top of QLabel?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.3k Views 1 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.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by kitfox
    #1

    I'm trying to implement that effect you see in some programs where you double click on a label and it temporarily changes into a line edit tool that lets you change the text.

    In one Java program I looked at, they do it by creating a new (Java equivalent of) QLineEdit widget and placing it over top of the label. When the user presses Enter, Esc or clicks away from it, they delete it again. I was wondering if I might be able to do something similar with Qt, and if so how I could get Qt to place my QLineEdit so it looks like it's in front of my QLabel?

    My purpose in all this is to create a control that acts similarly to a tree widget. I don't want to use the QTreeWidget because I'm doing some special handling for selection and drag and drop.

    J.HilkJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What special handling are you doing that makes you implement your own tree widget ?

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

      1 Reply Last reply
      0
      • K kitfox

        I'm trying to implement that effect you see in some programs where you double click on a label and it temporarily changes into a line edit tool that lets you change the text.

        In one Java program I looked at, they do it by creating a new (Java equivalent of) QLineEdit widget and placing it over top of the label. When the user presses Enter, Esc or clicks away from it, they delete it again. I was wondering if I might be able to do something similar with Qt, and if so how I could get Qt to place my QLineEdit so it looks like it's in front of my QLabel?

        My purpose in all this is to create a control that acts similarly to a tree widget. I don't want to use the QTreeWidget because I'm doing some special handling for selection and drag and drop.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @kitfox hi,
        I would say you have 2 easy ways to archive your goal

        1 use a QStackedWidget, and place the Laber on one page and the LineEdit on the other

        2 use QGridLayout, the addWidget function lets you stack widgets on top of each other, inside one cell.


        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
        2
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Do you want the QLabel to be visible behind the QLineEdit ? If yes, then you need to QLabel and QLineEdit as parent & child.

          If you don't care about the QLabel to visible when you click on it, as suggested by the @J-Hilk , you can use QStackedWidget. It is ideal solution.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          1
          • K Offline
            K Offline
            kitfox
            wrote on last edited by
            #5

            I solved this by creating a QDialog with a QLineEdit inside it and hiding the dialog's frame. This way I can position the line edit wherever I wish.

            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