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. Widget Ownership
Qt 6.11 is out! See what's new in the release blog

Widget Ownership

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.0k 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.
  • B Offline
    B Offline
    BrianE
    wrote on last edited by
    #1

    Just starting so checking a thing:
    If I create an widget in mainwindow then mainwindow will normally own it and I can refer to it as eg plainTextEdit within mainwindow's functions. Yes?
    If I create a widget via the designer then it would seem that the ui owns it and I always have to refer to it as ui->plainTextEdit. Is that right? It seems a bit cumbersome. Perhaps I've got it wrong. Perhaps there's a better way to do things. Perhaps there's some kind of shortcut or reference mechanism. I am a bit puzzled.

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

      Hi,

      When creating a complex widget using Designer, yes, you have to use ui->plainTextEdit since that class is generated from the XML built by Designer.

      Is it cumbersome ? It's rather a question of whether you like to build your UI using Designer or do everything by hand. No, there's no shortcut to avoid ui->something when you want to do something with an element of that widget.

      If that's something you really don't like it, then you have the alternative to write your own widget completely by hand. It really is just a matter of taste.

      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
      • B Offline
        B Offline
        BrianE
        wrote on last edited by
        #3

        Thanks, that's all I needed to know. It means I've got the right idea and can proceed. What I will probably do is to create a reference to such objects within mainwindow eg QPlainTextEdit *PTEd = ui->plainTextEdit, and use that.

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

          Frankly, that will just add clutter to your code and make it less understandable when you (or someone else) re-read it later.

          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
          • B Offline
            B Offline
            BrianE
            wrote on last edited by
            #5

            OK, I take your point. I guess I'm used to dear old BCB6 where that didn't happen. It's a paradigm I'm not familiar with and after all it only needs a bit of copy/paste, doesn't it. And it will ensure that I know where objects come from. So, yeah.

            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