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. Design of custom dynamic interface
Qt 6.11 is out! See what's new in the release blog

Design of custom dynamic interface

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

    hello.
    I have a interface system that fills dinamically a container layout with a series of widgets from the pression on an entity that can be a different shape object with his class(triangle , rectangle ecc...).
    Each click event of each widget must be connected to a only slot runtime.
    Only a slot because i don't know how many widget(and relative functionality)I have because the rectangle entity for example has 3 events with relative 3 widgets with icon and text different from the the circle entity that has 2 events(and two widget) ecc...

    I wish implement a connect function that create the signal / slot connection in each widget class.

    the problem are:

    1)how i can create a generic slot for connect each signal of each widget click event that manage the "sender" the widget that emit the event?

    i think sometings like:
    [code]
    class widgetBase: public widget
    {
    public:
    virtual void connect(object* pReceiver);
    }

    class customWidget : widgetBase
    {
    void connect(object* pReceiver){
    connect(this,SIGNAL(click()), pReceiver,SLOT(doWidgetClick(this)))

     }
    

    }

    class shape
    {
    public:
    virtual long GetWidgetCount();
    virtual widgetBase GetWidgetAt(int idx);
    virtual AddWidgetBase AddWidgetAt(widgetBase * pW);
    virtual RemoveWidgetBase RemoveWidgetAt(int idx);
    protected:
    Vector<widgetBase*>* m_pVectorWidget;

    }

    class circle : public Shape
    {
    long GetWidgetCount();
    widgetBase GetWidgetAt(int idx);
    AddWidgetBase AddWidget(widgetBase * pW); // i insert 2 widget
    RemoveWidgetBase RemoveWidgetAt(int idx);
    };
    class rectangle : public Shape
    {
    long GetWidgetCount();
    widgetBase GetWidgetAt(int idx);
    AddWidgetBase AddWidget(widgetBase * pW); // i insert 5 widget
    RemoveWidgetBase RemoveWidgetAt(int idx);
    };

    class MainDialog{

    void selectShape(Shape* pShape)
    {
    layout->clear();
    for(int i = 0; i < pShape->GetWidgetCount; i++)
    {
    widgetBase* pw = pShape->m_GetWidgetAt(i);
    pw->connect(this);
    layout->addWidget(pw, this);
    }
    }
    slot:
    void doWidgetClick(customWidget * pSender)
    {
    //now i have the widget that is clicked pSender!!!!
    }
    [/code]

    may be is a good design?
    thanks for advice.
    by

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I'm not quite sure about your requirements, but QWidget (more specifically QObject) has a sender() method, which allows for retrieving the emitting object within a slot.
      @
      void doWidgetClick()
      {
      CustomWidget pSender = qobject_cast<CustomWidget>(sender());
      }
      @
      For the "correct" solution design-wise you should consider using a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html.

      As to your code:

      • You cannot pass values using the connect() statement.
        @
        // WRONG, this is a value, not a type
        connect(this, SIGNAL(click()), pReceiver, SLOT(doWidgetClick(this)));
        idget*)));
        @
      • Slots can only have less, not more arguments (excluding signal default arguments).
        @
        // WRONG, slot has more arguments than signal
        // RIGHT, only if click signal has at least one default argument
        connect(this, SIGNAL(click()), pReceiver, SLOT(doWidgetClick(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