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. QButtonGroup for custom buttons
Forum Updated to NodeBB v4.3 + New Features

QButtonGroup for custom buttons

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.9k 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.
  • T Offline
    T Offline
    Texture
    wrote on last edited by
    #1

    Hello all! I faced with the following issue: can not correctly create QButtonGroup for my own buttons derived from QAbstractButton. In widget grouping several radio or pushbuttons is okay, but grouping my custom buttons fails. In this cases QButtonGroup is created (in QtCreator object window), but, as I could see in ui_xxx.h file, there is no creating of the object QPushButton: just declaring it. Looks like there is something that I have missed when was creating my buttons. Where could I find the root of my issue?

    Thank in advance!

    <Qt version 5.13, Linux x64>

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

      Hi
      What you mean excactly?
      Do you promote QPushbuttons to your custom pushbuttons and then try to make a group or
      how do you do it ?

      T 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        What you mean excactly?
        Do you promote QPushbuttons to your custom pushbuttons and then try to make a group or
        how do you do it ?

        T Offline
        T Offline
        Texture
        wrote on last edited by
        #3

        @mrjj not promote, but previously I have created a widget and plugin's library to use it with QtDesigner. Then I added my custom button from widget library (left window in QtCreator) and tried to assign to button group.

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

          Hi
          Ok so its a true custom button from a Designer plugin.
          Does the button work in all other regards ?

          Im have not tried withb a true custom button. There could be some issue even
          i dont see why.

          So the code generated in the UI_ file is not correct or what happens ?

          T 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Ok so its a true custom button from a Designer plugin.
            Does the button work in all other regards ?

            Im have not tried withb a true custom button. There could be some issue even
            i dont see why.

            So the code generated in the UI_ file is not correct or what happens ?

            T Offline
            T Offline
            Texture
            wrote on last edited by Texture
            #5

            @mrjj Yes, I can see it in QtDesigner, paintEvent works well, this button is working (being placed in different widgets) well too.

            If I place 2 QPushButtons and create QButtonGroup of them, QtCreator places in the ui_mywidget.h following lines:

            class Ui_mywidget {
            public: 
            <...>
                QButtonGroup *buttonGroup;
            
                void setupUi(QWidget *Chamber)
                {
                    pushButton = new QPushButton(groupBox);
                    buttonGroup = new QButtonGroup(MyWidget);
                    buttonGroup->setObjectName(QStringLiteral("buttonGroup"));
                    buttonGroup->addButton(pushButton);
                    pushButton->setObjectName(QStringLiteral("pushButton"));
            
                    gridLayout_main->addWidget(pushButton, 6, 0, 1, 1);
            
                    pushButton_2 = new QPushButton(groupBox);
                    buttonGroup->addButton(pushButton_2);
                    pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
            
                    gridLayout_main->addWidget(pushButton_2, 6, 1, 1, 1);
                }
            }
            

            Assigning my two custom button creates only

            class Ui_mywidget {
            public: 
            <...>
                QButtonGroup *buttonGroup_2;
            }
            

            Without any creating (with new operator) neither adding my custom buttons.
            I hope I've described my issue clearly :)

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              yes its very clear.
              Seems like a bug.

              it seems that Creator allow you to make it visually but then fails to
              generate the code.
              Just to be 100% sure, you select your custon buttons and do
              alt text

              ?

              T 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                yes its very clear.
                Seems like a bug.

                it seems that Creator allow you to make it visually but then fails to
                generate the code.
                Just to be 100% sure, you select your custon buttons and do
                alt text

                ?

                T Offline
                T Offline
                Texture
                wrote on last edited by
                #7

                @mrjj Yes. Moreover, I have tried two ways: use this context menu from the central window (graphical ui) and from the right window (objects list). just in case :)

                I don't know, is it important or not, but this assignment includes QButtonGroup header in ui_chamber.h too:

                #include <QtWidgets/QButtonGroup>
                
                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Well its a bit odd as normally the options is just not there is not right classes/types so since it allows it, one should think it should work.
                  Give it some hours and see if someone has an idea.
                  I know writing a small sample is a bit hard as its a plugin.

                  Im trying to find some other Designer button i could try with and see if it generally do not work
                  or there could be something in the plugins XML or similar that needs filling out.

                  1 Reply Last reply
                  2

                  • Login

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