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 place widgets by specifying positions in QFrame
Forum Update on Monday, May 27th 2025

How to place widgets by specifying positions in QFrame

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 3.9k 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.
  • W Offline
    W Offline
    wabisuke2718
    wrote on last edited by wabisuke2718
    #1

    Please tell me how to place widgets by specifying positions in QFrame by program.
    I couldn't use frame->addWidget() method.
    I don't want the widgets laid out automatically.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Give the child widget a parent and then you can use setGeometry() or move() and resize().
      For example:

      QFrame* parentWidget = new QFrame();
      QPushButton* childWidget = new QPushButton("Hello!", parentWidget); //the parent is what's important here
      childWidget->setGeometry(10, 10, 200, 100);
      
      W 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        Give the child widget a parent and then you can use setGeometry() or move() and resize().
        For example:

        QFrame* parentWidget = new QFrame();
        QPushButton* childWidget = new QPushButton("Hello!", parentWidget); //the parent is what's important here
        childWidget->setGeometry(10, 10, 200, 100);
        
        W Offline
        W Offline
        wabisuke2718
        wrote on last edited by wabisuke2718
        #3

        @Chris-Kawa
        Thank you for answering.
        I could place widgets like that.
        But how to properly arrange widgets whose size changes like labels.
        I would like to calculate the vertical size that varies depending on the label text with fixed width.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sure, you could do that using boundingRect(), but it sounds like you want to manually redo what the layout does for you. Are you sure you don't want it? What's your usecase exactly?

          W 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            Sure, you could do that using boundingRect(), but it sounds like you want to manually redo what the layout does for you. Are you sure you don't want it? What's your usecase exactly?

            W Offline
            W Offline
            wabisuke2718
            wrote on last edited by
            #5

            @Chris-Kawa
            I'm trying to make a Mastodon client application.
            So I am planning to display toot in conjunction with two QFrames.
            Specifically, move the toot that came to the bottom of the left QFrame to the top of the right QFrame.
            Also, if one toot is separated by the upper or lower end of the QFrame, it is displayed partly in two QFrames.

            This is what I want to do, but when I use to use setGeometry when displaying toot as shown in the figure,
            the text will be interrupted halfway.
            I wanted to fix this and I asked you any additional questions earlier.

            alt text

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

              Hi,

              Shouldn't this rather be implement with a QListView and a custom QStyledItemDelegate ?

              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
              1

              • Login

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