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. Best way to change change Widgets on a layout depending on a value of a Qcombobox in a QFormLayout?
Forum Updated to NodeBB v4.3 + New Features

Best way to change change Widgets on a layout depending on a value of a Qcombobox in a QFormLayout?

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

    Im using a QFormLayout, where each row I have a Horizontal Layout. Inside this Layout I have a QComboBox and other widgets that depend on the value of the combo box. If for example the index of the combo box is 1 I have a QLineEdit, a check box and a label but if the index value of the combobox is changed the checkbox and label should be hidden or replaced by another widget.

    The problem Im facing is that each time I change the Combobox I dont know in which row from the Formlayout the user has changed the value. Is there a method or member I can use from the combobox or formlayout to know this?

    My current Idea is to just save the current index of each combobox and compare it again when the change has been done to know which combobox in the formlayout has been changed.

    alt text

    Is there another way to deal with this?

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

      Hi and welcome to devnet,

      Sounds like you should use a QStackedWidget. You can then connect the combo box indexChanged signal to the QStackedWidget::setCurrentIndex slot directly.

      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
      2
      • qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by qwasder85
        #3

        I would create a widget from the controls and instance the widget for every row. This way, the handling of showing/hiding/replacing of controls can happen internally in this widget and it doesn't even have to be aware of other instances in the other rows.
        This can be combined with SGaist's method of swapping single controls within the widget.
        Does that make sense?

        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