Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. SIGNAL and SLOTS

SIGNAL and SLOTS

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 4.2k 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.
  • D Offline
    D Offline
    dleviathan
    wrote on last edited by
    #1

    I have QList<QPushButton > as this:
    @
    for(int i = 0; i < 5; i++)
    {
    for(int j = 0; j < 5; j++)
    {
    QPushButton _btnTemp = new QPushButton(_subWidget);
    _btnTemp->setGeometry(i
    40, j
    40, 40, 40);
    _arrBtn->append(_btnTemp);
    }
    }
    @
    with
    @_arrBtn = new QList<QPushButton *>();@
    How i can catch signal, slot on each button?
    I want when i click on any button, other buttons in cross with it will be changed color? how i can do?
    Thanks for support!!!

    P/S:sry, my English not good!

    1 Reply Last reply
    0
    • BilbonSacquetB Offline
      BilbonSacquetB Offline
      BilbonSacquet
      wrote on last edited by
      #2

      simply connect all the buttons signal pressed() to one slot, and in response set the color:

      @Xxx:init()
      {
      for(int i = 0; i < 5; i++)
      {
      for(int j = 0; j < 5; j++)
      {
      QPushButton _btnTemp = new QPushButton(_subWidget);
      connect(_btnTemp, SIGNAL(pressed()), this, SLOT(buttonPressed()));
      _btnTemp->setGeometry(i
      40, j* 40, 40, 40);
      _arrBtn->append(_btnTemp);
      }
      }
      }

      XXx::buttonPressed()
      {
      QPushButton* btn_pressed = static_cast<QPushButton*>(sender());
      int pos = _arrBtn->indexOf(btn_pressed);
      }@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Or, you look into using [[doc:QSignalMapper]].

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dleviathan
          wrote on last edited by
          #4

          [quote author="BilbonSacquet" date="1321433222"]simply connect all the buttons signal pressed() to one slot, and in response set the color:

          @Xxx:init()
          {
          for(int i = 0; i < 5; i++)
          {
          for(int j = 0; j < 5; j++)
          {
          QPushButton _btnTemp = new QPushButton(_subWidget);
          connect(_btnTemp, SIGNAL(pressed()), this, SLOT(buttonPressed()));
          _btnTemp->setGeometry(i
          40, j* 40, 40, 40);
          _arrBtn->append(_btnTemp);
          }
          }
          }

          XXx::buttonPressed()
          {
          QPushButton* btn_pressed = static_cast<QPushButton*>(sender());
          int pos = _arrBtn->indexOf(btn_pressed);
          }@[/quote]

          Thanks for support! when i did as u say i have a problem:
          my index in _arrbtn have shape:
          0 1 2 3 4
          5 6 7 8 9
          ....
          when pos i taked have shape:
          0 5 10 ....
          1 6
          2 7
          3 8
          4 9...
          which way i can solve it? thanks u again :)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            On line 9 of BilbonSacquet's post, you might swap the use of i and j.

            1 Reply Last reply
            0
            • BilbonSacquetB Offline
              BilbonSacquetB Offline
              BilbonSacquet
              wrote on last edited by
              #6

              Yes, I just give the principle ... it's not a working solution.
              The pos should reconstruct into i/j position: with % and /.
              You could too derivate QPushButton to store the position, you could even think to create a slot changeColor() and connect directly the pressed() signal to the slot changeColor()....
              To help you more I need a concrete implementation ... :)

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dleviathan
                wrote on last edited by
                #7

                now, i changed QPushButton = QTextEdit. So how to catch Signal when i clicked on TextEdit i had created - not Signal(TextChanged);
                thanks for support!

                P/s: sry because spam, i have just solved it :">

                1 Reply Last reply
                0
                • BilbonSacquetB Offline
                  BilbonSacquetB Offline
                  BilbonSacquet
                  wrote on last edited by
                  #8

                  There is no signal sends only by click into a QTextEdit. Because you need a signal only if something change and of course by clicking in a text field make no change in the content (you should begin at least to select).

                  Now if you want anyway one, inherits the QTextEdit and overload the mousePressEvent() and send a signal from here.

                  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