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. Showing widgets on Tab and/or button
Qt 6.11 is out! See what's new in the release blog

Showing widgets on Tab and/or button

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

    Hello,

    I'm looking for a way to create a widget that displays input controls, let's say line edits. But to simplify it for the users, I don't want to show all of them since only a couple are relevant and others are optional. What I'd like is to initially show all the mandatory fields and then a small button saying "more >>" that would display other fields. I think there was a Qt example with such a functionality but I can't find it at the moment.

    But, along with the button, I would like to also show the remaining widgets when the user presses Tab key on the last mandatory line edit. So the program works in such a way that: widget with 3 line edits and a "more >>" button is displayed (Save and Cancel too of course), focus is on LineEdit_1. User fills in the data, presses tab to switch to LineEdit_2, data, tab, LineEdit_3, data. Now, if the user presses tab again, the widget is extended and a couple of more line edits are shown.

    Any good ideas on how to do it?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      its the "Expandable dialog example":http://doc.trolltech.com/4.7/dialogs-extension.html
      You could derive your button and check,whether the the focus is set there by tab and call expand...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mjakubowski
        wrote on last edited by
        #3

        Thanks, that's the example I was looking for!

        As for tab - I'd rather not have focus on the button using tab, direct focus switch from the last initially visible line edit to the first one that is hidden is what I'm after.

        But the idea is quite good, thanks! I think I could subclass the last line edit and reimplement QWidget's focusOutEvent, check for reason() == Qt::TabFocusReason and if so, show the extension widget and set focus to the first edit there.

        Correct me if I'm wrong here.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          That is also a possibility, but I would overwrite keyEvent, not focusOut.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mjakubowski
            wrote on last edited by
            #5

            Any reasons for that? Faster, more elegant?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              Then you can catch the key on it's source, emit a signal that can show the new widgets and then set the focus directly to the needed widgets. If you do it on focusOut, the focus already went to another widget (perhaps the button??).
              From my opinion, that is a more clear solution, as you want to react on a key event, not on a focus event. The focus is the result, not the reason, isn't it?

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              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