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. Unexpected behavior of the QStackedWidget when I insert twice or more the same QWidget (Wrong position of QWidget).
Forum Updated to NodeBB v4.3 + New Features

Unexpected behavior of the QStackedWidget when I insert twice or more the same QWidget (Wrong position of QWidget).

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 414 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.
  • CP71C Offline
    CP71C Offline
    CP71
    wrote on last edited by CP71
    #1

    I hope this is the correct place to report a possible issue.

    If in a QStackedWidget I insert more of once the same QWidget, all QWidgets are in the wrong position. (Please see image and application output)

    Expected behavior is:
    Pos pWidget1 0
    Pos pWidget2 1
    Pos pWidget3 2
    Pos pWidget4 4

    m_pageStack->indexOf(pWidget1); I Expected the first position of item, in my case 0.

    I reproduce this behavior in Windows and Linux, Qt4 and Qt5.

    13ccb5ce-9237-42cb-adc9-fdf83233b001-image.png

    Best regards

    VRoninV 1 Reply Last reply
    0
    • CP71C CP71

      I hope this is the correct place to report a possible issue.

      If in a QStackedWidget I insert more of once the same QWidget, all QWidgets are in the wrong position. (Please see image and application output)

      Expected behavior is:
      Pos pWidget1 0
      Pos pWidget2 1
      Pos pWidget3 2
      Pos pWidget4 4

      m_pageStack->indexOf(pWidget1); I Expected the first position of item, in my case 0.

      I reproduce this behavior in Windows and Linux, Qt4 and Qt5.

      13ccb5ce-9237-42cb-adc9-fdf83233b001-image.png

      Best regards

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @CP71 said in Unexpected behavior of the QStackedWidget when I insert twice or more the same QWidget (Wrong position of QWidget).:

      I Expected the first position of item, in my case 0.

      There is no first and second. When you call addWidget the widget gets taken out of wherever it was parented to and moved as a child of the stacked page. when you call addWidget(pWidget1) the second time you are moving the widget from pos 0 to pos 2

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @CP71 said:

        If in a QStackedWidget I insert more of once the same QWidget, all QWidgets are in the wrong position.

        A given widget object can appear only once in the stack. If you insert the same Widget1 object twice then it moves from where it was after to the first insert to where you put it the second time. This causes stack indices to change (there are no index gaps like your expectation). This what your code does.

        If you insert two separate instances of a Widget1 widget then you will get two visually identical but independent pages in the stack. Doing this would give you five widgets in the stack: Widget1, Widget2, Widget3, Widget1, Widget4.

        If you want a totally blank page in the stack (cannot think why) then just insert a bare QWidget object.

        CP71C 1 Reply Last reply
        4
        • C ChrisW67

          @CP71 said:

          If in a QStackedWidget I insert more of once the same QWidget, all QWidgets are in the wrong position.

          A given widget object can appear only once in the stack. If you insert the same Widget1 object twice then it moves from where it was after to the first insert to where you put it the second time. This causes stack indices to change (there are no index gaps like your expectation). This what your code does.

          If you insert two separate instances of a Widget1 widget then you will get two visually identical but independent pages in the stack. Doing this would give you five widgets in the stack: Widget1, Widget2, Widget3, Widget1, Widget4.

          If you want a totally blank page in the stack (cannot think why) then just insert a bare QWidget object.

          CP71C Offline
          CP71C Offline
          CP71
          wrote on last edited by CP71
          #4

          @ChrisW67
          Thanks to all.
          I don't have a qwidget twice in the QStackedWidget,
          I was porting a Linux application to Windows when for compile issue in a UI I temporarily switched it with one that already exists because I have some defines with indexes of pages.
          When I have inserted twice the same qwidget all my defines were not related to the real position of widgets, up at once it seemed strange to me.
          Yes, I did as you say, I have temporarily inserted an empty QWidget.

          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