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 stop QLabel and QPushbutton from expanding????
Forum Updated to NodeBB v4.3 + New Features

How to stop QLabel and QPushbutton from expanding????

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.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.
  • T Offline
    T Offline
    tjrob
    wrote on last edited by
    #1

    This is driving me crazy. I just want a QLabel and a QPushButton, each initialized with plain text, to sit together on the left side of one row inside an enclosing widget with a QVBoxLayout; together they are much narrower than the enclosing widget. No matter what I have tried they expand in one way or another. As the QPushButton text is either "+" or "-", I could call setMaximumSize(16) and that works for it; my class doesn't know the width of the label text. But there must be a better way. No attempt using QSizePolicy has worked for me.

    How can I get them to look like this at the left side of the enclosing widget:
    Label Text [+]
    (here the QPushButton is mimicked by [].)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Buckets
      wrote on last edited by
      #2

      So you have a button of known size, and a label of unknown size that are contained in a widget and you want their placement to be fixed.


      | <-- this representing the widget, text,and button

      |_________|
      Do you have to place them within the QVBoxLayout? Why not tie them directly to the parent and use setGeometry to fix their placement within the parent?

      ba ba ba
      ba na na na

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tjrob
        wrote on last edited by
        #3

        If I attempted to use fixed geometry in the parent, I would have to carefully keep track of the pixel position of every widget in it; there are a lot of them. That's a LOT of work, and would be quite fragile; the whole point of using layouts is to avoid that sort of thing. Moreover, I don't know how much space to allocate for each.

        Why is it so hard in Qt to place widgets side-by-side without expanding? Or am I missing something rather obvious? After all, in HTML that's just natural. As it happens, I am translating dialog boxes from HTML to Qt (long, sad, story).

        I guess I'm looking for the analog to Java's FlowLayout....

        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