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 to acces button from another form
Forum Updated to NodeBB v4.3 + New Features

How to acces button from another form

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 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.
  • K Offline
    K Offline
    Krzychu
    wrote on last edited by Krzychu
    #1

    Hello

    I've got such a problem: I created a form with class and this form include secondone only .ui form (without class files, just a tamplate of layout). Inside this other form i've got a few buttons and I want to listen if their are pressed. It is not possible with option [go to slot]. I have to add the second form is inside a tabWidget, but buttons should do same action for any tab.

    Please advice me some solution.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      michelson
      wrote on last edited by
      #2

      If i understand correctly you try to apply your "second" form to one of the QTabWidget TabWidgets (:D)?
      I guess you can ui->setupUi(this) for every QTableWidget QWidget. This means that you can call wanted QWidget::Ui object - in this case QButton like tabWithCustomForm->ui->buttonOne if i understand correctly.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Krzychu
        wrote on last edited by
        #3

        Acctualy I've solve this problem. What i needed were to get handler to QButton from the form added dynamicly to QTabWidget.
        I created 2 lists; forms and tabs(QWidget type) and for each form I used setupUi() for tabs.
        Due to QButton name was declared in diffrent form it was "invisible" from class attatched to main window form.
        As solution every time when tab is changed I looked for its handler by name
        ui->tabWidget->findChild<QPushButton *>("buttonName");
        then connect new handler to slot of button_pressed_function() after pressed() event
        Do You think it could by done without find metod?

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

          Hi and welcome to devnet,

          Do you have any constraint to have your second widget as a UI only object ? Why not have it as normal widget and give it an interface that you can connect properly without the need to know the internals of the widget ?

          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
          0
          • K Offline
            K Offline
            Krzychu
            wrote on last edited by
            #5

            I find QT Designer Form and at first moment I've thought that will do the work, but later I added buttons and things get more complicated. Actually I've added to QTabWidget new widgets and apply the form to them.
            I wonder if tabs added as form class( created by designer) have some implemented connection with containing the QTabWidget class(QMainWindow in my case), or it's necessary to pass a handle.

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

              There's no particular connections created automatically. It's your role to do that.

              You should create your widgets with designer, give them an interface so you can then easily re-use them within other widgets. By interface, I don't mean give access to their own internal widgets because that's an implementation detail that should not be known outside. e.g. if one of your widget is a QDialog based widget, you should not try to connect to the ok button that you have in that widget, but connect to the accepted signal from QDialog.

              On a side note, It's pretty unusual to put a QMainWindow in a QTabWidget.

              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
              0

              • Login

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