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. QStackedWidget: Bind to combo box?
Forum Updated to NodeBB v4.3 + New Features

QStackedWidget: Bind to combo box?

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

    Hello,

    Is it possible to "bind" (sorry for the .net term), the list of available widgets in a QStackedWidget to a combo box?

    The "docs":http://doc.qt.nokia.com/latest/qstackedwidget.html show using a combo box, but only via a manual and fragile setup.

    Can a QComboBox just automatically display the available pages?

    Thank you

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

      Not out of the box. You will have to add some code yourself.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nonot1
        wrote on last edited by
        #3

        Two questions:

        1. Is there a canonical / well-accepted way to bind the combobox to the stack widget content and state?

        2. As a separate effort, if I wanted to wrap this in a (designer friendly) custom widget, how would I do that?

        Thank you

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

          No, there is no standard way to do this. You will have to connect to a signal of the combobox and call some slot on the stacked widget. As an outline:

          • "QStackedWidget::addWidget() ":http://doc.qt.nokia.com/4.7/qstackedwidget.html#addWidget returns an int - store that
          • call "QComboBox::addItem() ":http://doc.qt.nokia.com/4.7/qcombobox.html#addItem and use the stored int for the user data of the new item
          • connect a slot of your own to the signal "activated(int) ":http://doc.qt.nokia.com/4.7/qcombobox.html#activated of your combo box
          • retrieve the user data (= index in stacked widget) with "QComboBox::itemData() ":http://doc.qt.nokia.com/4.7/qcombobox.html#itemData
          • use the int to switch to the desired widget using "QStackedWidget::setCurrentIndex() ":http://doc.qt.nokia.com/4.7/qstackedwidget.html#currentIndex-prop

          http://www.catb.org/~esr/faqs/smart-questions.html

          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