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. Widget class customisation
Forum Updated to NodeBB v4.3 + New Features

Widget class customisation

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

    Hi All,

    I have connected three widgets of the same class (CurrentButtonOne)to three different slots as shown below. Where the signal is getValue

    connect(ui->widget_currentOne, &CurrentButtonOne::getValue, this, &stageProgram::setCurrOnChannelOne);
        connect(ui->widget_currentTwo, &CurrentButtonOne::getValue, this, &stageProgram::setCurrOnChannelTwo);
        connect(ui->widget_currentThree, &CurrentButtonOne::getValue, this, &stageProgram::setCurrOnChannelThree);
    
    

    where in the CurrentButtonOne class , have a parameter called value:

    #ifndef CURRENTBUTTONONE_H
    #define CURRENTBUTTONONE_H
    
    #include <QWidget>
    
    class Timer;
    
    namespace Ui {
    class CurrentButtonOne;
    }
    
    class CurrentButtonOne : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit CurrentButtonOne(QWidget *parent = nullptr);
        ~CurrentButtonOne();
    
    private slots:
    
        void buttonPressed_high();
        void buttonReleased_high();
        void buttonPressed_moreHigh();
        void buttonReleased_moreHigh();
    
    signals:
        void getValue(unsigned int);
    
    private:
        Ui::CurrentButtonOne *ui;
        int value = 0 ;  //---> assign different values based on the slots which is connected
    };
    
    #endif // CURRENTBUTTONONE_H
    
    

    Here I need to assign different values to value depending on which slot it is connected. Is it something possible?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No, and it raises a big question: why shall that value be different base on a slot ?

      In normal operation, the object that emits a signal does not know nor should it care about what is connected to it. Sounds like you are trying to make that widget know way to much about what it interacts with.

      Can you explain your use case ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • V Offline
        V Offline
        viniltc
        wrote on last edited by
        #3

        @SGaist Hi

        Use case is as follows:

        My widget (of class CurrentButtonOne ) is inc/dec button looks like this, I've three of them:

        ss.JPG

        This widget is initially built to increment/decrement value send this as signal , and connected to three slots.

        previously the starting value was 0. So assigned value as zero:

        private:
            Ui::CurrentButtonOne *ui;
            int value = 0 ;
        

        But now I've got a situation in which the starting value can be different for each of the widgets and need to increment/decrement from that starting value (not zero).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you should configure each of these widgets explicitly.

          That will make both your code cleaner and clearer.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved