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. [SOLVED] QList<CustomWidget*> : how to get a handle to its contents
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QList<CustomWidget*> : how to get a handle to its contents

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.0k 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.
  • C Offline
    C Offline
    Code_ReaQtor
    wrote on last edited by
    #1

    I have a class CustoWidget which subclasses QWidget

    I need multiple of it so I stored them inside QList:
    @QList<CustomWidget*> manager;@

    Inside "function1()", I initialized each CustomWidget everytime I call this function and add them to the list
    @CustomWidget *widget = new CustoWidget();
    manager.append(widget);
    widget->show();@

    Within "function2()", I need to retrieve all CustomWidget in the list to reposition them:
    @CustomWidget *widget;
    foreach(widget,manager)
    {
    widget->move(x,y); // x and y were retrieved using QDesktopWidget and doesn't matter in the code
    }@

    but after function2() is called the CustomWidgets disappears but they are still inside the QList.

    Note: The CustomWidgets are small non-modal sub-windows similar to QDialog but with specific purpose

    I can't use signal and slot since they will stack up when there are multiple CustomWidgets and I think its impractical to track them when some were closed by the user;

    Please visit my open-source projects at https://github.com/Code-ReaQtor.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      That is a strange setup, but this is not the question.
      @
      foreach (CustomWidget *w, manager) {
      w->move(x,y);
      }
      @
      this is the standard way of using foreach. Maybe x, and y are too big and place your widgets outside the visible region of desktop?

      (Z(:^

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        I don't seem to grasp your actual problem.

        So your widgets disappear after <code>widget->move(x, y)</code>? You most probably moved then to a non-visible area then (out of screen). Use <code>qDebug() << x << y;</code> within your loop (don't forget to <code>#include <QtDebug></code>) to find out where they are actually moved to.

        1 Reply Last reply
        0
        • ZlatomirZ Offline
          ZlatomirZ Offline
          Zlatomir
          wrote on last edited by
          #4

          I don't really understand your problem, so:
          the problem is the disappear? if so don't they disappear because x,y point is outside of screen?

          or answer to the question in the title is you can use one of QList's members: "operator[]":http://qt-project.org/doc/qt-4.8/qlist.html#operator-5b-5d or "value()":http://qt-project.org/doc/qt-4.8/qlist.html#value or "at()":http://qt-project.org/doc/qt-4.8/qlist.html#at example: manager.value(0)->customWidgetfunctionality();

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Code_ReaQtor
            wrote on last edited by
            #5

            Thanks sierdzio and Lukas Geyer and Zlatomir!

            It works now. I also got the question in my mind that I know I am doing the right thing, why it isn't working?

            Apparently, x and y became "negative" so they became invisible. There is just a small problem with computing for the x's and y's of each CustomWidget. I always used QDebug in all my codes, I just missed "x and y" this time. My Bad!

            Thanks! I appreciate your help.

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            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