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. QDialog auto fit content
Forum Updated to NodeBB v4.3 + New Features

QDialog auto fit content

Scheduled Pinned Locked Moved Solved General and Desktop
qdialogqlistwidgetqtcreator
4 Posts 3 Posters 3.7k 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.
  • Gianluca86G Offline
    Gianluca86G Offline
    Gianluca86
    wrote on last edited by
    #1

    Hi everyone,

    I have a Dialog with a QListWidget and two buttons.
    As I add dynamically the QListWidgetItem, I would like that the window adapts in real time to the size of what I post.
    it's possible to do it?
    The QListWidgetItem are simple texts with a small icon and Dialog is created with QtCreator.

    I have already tried to put SizePolicy Exspandig, or use adjusteSize in the code, or resize, but nothing.
    Thank you

    jsulmJ 1 Reply Last reply
    0
    • Gianluca86G Gianluca86

      Hi everyone,

      I have a Dialog with a QListWidget and two buttons.
      As I add dynamically the QListWidgetItem, I would like that the window adapts in real time to the size of what I post.
      it's possible to do it?
      The QListWidgetItem are simple texts with a small icon and Dialog is created with QtCreator.

      I have already tried to put SizePolicy Exspandig, or use adjusteSize in the code, or resize, but nothing.
      Thank you

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

      @Gianluca86 That would be quite unusual design! Why should the whole dialog resize if you put more values in the list? The list shows a scrollbar if not all values are visible. It should be up to the user to resize the dialog if he/she wants to.
      At least I wouldn't like such UI (and never seen so far)...

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

      1 Reply Last reply
      0
      • jerome_isAviableJ Offline
        jerome_isAviableJ Offline
        jerome_isAviable
        wrote on last edited by
        #3

        It may be possible but difficult/clunky (that is maybe why no one answer to...) and i think a strange design.
        Because when your list will grow, at the same time the QDialog bow will have his height grow, and when his height will become bigger than the screen height, so... you will loose the access of the full QDialog box.
        I think a "good" idea is maybe to set a default minimumSize for the QListWidget, and then if more items will be include, automatically it should have a scroll vertical bar that appears.
        If you really want to adapt size of the QDialogBox you have to link event of new item added to a slot you made for resize the QDialogBox window (somethink like Height-of-Window = the items number*height/item-height-size).
        Like that, each event time of add/remove item in your list, the slot linked with member function for resize the dialog box window will be call.
        Look at QObject::connect in the Qt5 API for learn how to connect SIGNAL with SLOT... a SLOT is a member function you can link with signal, a signal is... a signal emit from event (or you can call signal yourself from "emit" function), this is the concept mechanism with Qt to make things dynamic.

        1 Reply Last reply
        0
        • Gianluca86G Offline
          Gianluca86G Offline
          Gianluca86
          wrote on last edited by
          #4

          I get it. Thanks so much

          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