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. How do i use the buttons from a vector of objects that have a member QPushButton * button in my Widget class?
Forum Update on Monday, May 27th 2025

How do i use the buttons from a vector of objects that have a member QPushButton * button in my Widget class?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 220 Views
  • 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.
  • B Offline
    B Offline
    Bebemc42
    wrote on 27 Dec 2022, 21:23 last edited by
    #1

    So i have a class Territory that has a member QPushButton * button and i have a class Game that inherits a QWidget, here i want the game to take place. This class has a vector of objects of type Territory. And my question is how i can use those buttons? That appear on the screen, but i don't know how to make a clicked() function that can be used by all of them. For example if i click a territory to color it another color. How can i do that?

    J 1 Reply Last reply 27 Dec 2022, 22:29
    0
    • B Bebemc42
      27 Dec 2022, 21:23

      So i have a class Territory that has a member QPushButton * button and i have a class Game that inherits a QWidget, here i want the game to take place. This class has a vector of objects of type Territory. And my question is how i can use those buttons? That appear on the screen, but i don't know how to make a clicked() function that can be used by all of them. For example if i click a territory to color it another color. How can i do that?

      J Offline
      J Offline
      JonB
      wrote on 27 Dec 2022, 22:29 last edited by JonB
      #2

      @Bebemc42
      Hello and welcome.

      If you have a number of buttons and you wish them to share a single clicked signal you might consider grouping them in a QButtonGroup and attaching a slot to its QButtonGroup::buttonClicked(QAbstractButton *button) signal.

      Or you could iterate the vector calling connect() on each one in turn to the same slot, possibly with a parameter.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        Bebemc42
        wrote on 28 Dec 2022, 20:10 last edited by
        #3

        That worked, thanks!:3

        1 Reply Last reply
        0

        2/3

        27 Dec 2022, 22:29

        • Login

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