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?
QtWS25 Last Chance

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 213 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 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?

    JonBJ 1 Reply Last reply
    0
    • B Bebemc42

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 last edited by
        #3

        That worked, thanks!:3

        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