qt - QPushButton click event inside a QStackWidget is sent to parent window -


i have mainwindow class , within qstackwidget. inside have 3 widgets, each 1 own custom class derived qwidget.

inside 1 of widgets have button.

when using qt creator , press go slot.. on button, creates on_button_clicked event in mainwindow class.

how change have event inside custom class?

update: can see buttons located in mainwindow. auto generated, not sure how move it.

code: mainwindow.cpp:

#include "mainwindow.h" #include  "ui_mainwindow.h" #include <qmessagebox>  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this); }  mainwindow::~mainwindow() {     delete ui; }  void mainwindow::on_pushbutton_2_clicked() {     qmessagebox::information(this, "button 2 clicked!", "click"); } 

mainwindow.ui

<?xml version="1.0" encoding="utf-8"?> <ui version="4.0">  <class>mainwindow</class>  <widget class="qmainwindow" name="mainwindow">   <property name="geometry">    <rect>     <x>0</x>     <y>0</y>     <width>668</width>     <height>630</height>    </rect>   </property>   <property name="windowtitle">    <string>mainwindow</string>   </property>   <widget class="qwidget" name="centralwidget">    <widget class="qstackedwidget" name="stackedwidget">     <property name="geometry">      <rect>       <x>10</x>       <y>10</y>       <width>531</width>       <height>391</height>      </rect>     </property>     <property name="currentindex">      <number>1</number>     </property>     <widget class="stack1" name="page">      <widget class="qpushbutton" name="pushbutton">       <property name="geometry">        <rect>         <x>140</x>         <y>110</y>         <width>321</width>         <height>121</height>        </rect>       </property>       <property name="text">        <string>button on stack1</string>       </property>      </widget>     </widget>     <widget class="stack2" name="page_2">      <widget class="qpushbutton" name="pushbutton_2">       <property name="geometry">        <rect>         <x>110</x>         <y>140</y>         <width>371</width>         <height>161</height>        </rect>       </property>       <property name="text">        <string>button on stack2</string>       </property>      </widget>     </widget>    </widget>   </widget>   <widget class="qmenubar" name="menubar">    <property name="geometry">     <rect>      <x>0</x>      <y>0</y>      <width>668</width>      <height>25</height>     </rect>    </property>   </widget>   <widget class="qtoolbar" name="maintoolbar">    <attribute name="toolbararea">     <enum>toptoolbararea</enum>    </attribute>    <attribute name="toolbarbreak">     <bool>false</bool>    </attribute>   </widget>   <widget class="qstatusbar" name="statusbar"/>  </widget>  <layoutdefault spacing="6" margin="11"/>  <customwidgets>   <customwidget>    <class>stack1</class>    <extends>qwidget</extends>    <header>stack1.h</header>    <container>1</container>   </customwidget>   <customwidget>    <class>stack2</class>    <extends>qwidget</extends>    <header>stack2.h</header>    <container>1</container>   </customwidget>  </customwidgets>  <resources/>  <connections/> </ui> 

i want button callback inside custom class stack2.cpp

#include "stack2.h"  stack2::stack2(qwidget *parent) : qwidget(parent) {  }  stack2::~stack2() {  } 

you made promotion correctly should not fill contents of promoted widgets in main window form (i.e. put buttons in them). instead, create stack page classes designer form classes (just mainwindow based on qwidget) , put contents in them using separate form editor. alternatively, can add layouts , buttons stack pages manually in constructors.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -