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. Change StackedWidget Pages With TreeWidget

Change StackedWidget Pages With TreeWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
stackedwidgettreewidgetsignal & slot
5 Posts 2 Posters 2.2k 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.
  • M Offline
    M Offline
    M4RZB4Ni
    wrote on 31 May 2016, 17:35 last edited by
    #1

    Hello,
    I Have a StackedWidget and TreeWidget in my Window
    I Want to Connect this Two Object,
    And I Wrote This Codes But None Of This Codes Worked!
    My Codes:

    #include "management_menu.h"
    #include "ui_management_menu.h"
    
    management_menu::management_menu(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::management_menu)
    {
        ui->setupUi(this);
        connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onTextChanged()));
       connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
        connect(ui->treeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
        connect(ui->treeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
        connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
    
    
    
    
    }
    
    management_menu::~management_menu()
    {
        delete ui;
    }
    
    
    

    What i must do?

    Thanks
    M4RZB4Ni

    C 1 Reply Last reply 31 May 2016, 18:12
    0
    • M M4RZB4Ni
      31 May 2016, 17:35

      Hello,
      I Have a StackedWidget and TreeWidget in my Window
      I Want to Connect this Two Object,
      And I Wrote This Codes But None Of This Codes Worked!
      My Codes:

      #include "management_menu.h"
      #include "ui_management_menu.h"
      
      management_menu::management_menu(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::management_menu)
      {
          ui->setupUi(this);
          connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onTextChanged()));
         connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
          connect(ui->treeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
          connect(ui->treeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
          connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
      
      
      
      
      }
      
      management_menu::~management_menu()
      {
          delete ui;
      }
      
      
      

      What i must do?

      C Offline
      C Offline
      c.savur
      wrote on 31 May 2016, 18:12 last edited by
      #2

      @M4RZB4Ni

      the signal and slot parameter does not match. Try to write your own slot then call stackwidget methods.

      example :

      connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(myslot(QTreeWidgetItem*,int)));
      
      in my slot:
      void management_menu::mySlot(QTreeWidgetItem*,int index) 
      {
           ui->stackedWidget->setCurrentIndex(index);
      }
      
      

      This should work.

      M 1 Reply Last reply 31 May 2016, 18:25
      0
      • C c.savur
        31 May 2016, 18:12

        @M4RZB4Ni

        the signal and slot parameter does not match. Try to write your own slot then call stackwidget methods.

        example :

        connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(myslot(QTreeWidgetItem*,int)));
        
        in my slot:
        void management_menu::mySlot(QTreeWidgetItem*,int index) 
        {
             ui->stackedWidget->setCurrentIndex(index);
        }
        
        

        This should work.

        M Offline
        M Offline
        M4RZB4Ni
        wrote on 31 May 2016, 18:25 last edited by M4RZB4Ni
        #3

        @c.savur
        this works but
        No more than once
        in Second click this those not work!

        Thanks
        M4RZB4Ni

        C 2 Replies Last reply 31 May 2016, 18:44
        0
        • M M4RZB4Ni
          31 May 2016, 18:25

          @c.savur
          this works but
          No more than once
          in Second click this those not work!

          C Offline
          C Offline
          c.savur
          wrote on 31 May 2016, 18:44 last edited by
          #4

          @M4RZB4Ni

          Yes, you are right it will work only one timer because, itemActivated(QTreeWidgetItem*,int), the second parameter is column id. So this will be same for the entire column.

          One way to do is that set some information to QTreeWidgetItem and in myslot use this information to call stackedWidget methods.

              QTreeWidgetItem *s = new QTreeWidgetItem();
          // set data
              s->setData(0, Qt::UserRole, QVariant("1"));
           
          // obtain data   
              QVariant data = s->data(0, Qt::UserRole);
          
          
          1 Reply Last reply
          0
          • M M4RZB4Ni
            31 May 2016, 18:25

            @c.savur
            this works but
            No more than once
            in Second click this those not work!

            C Offline
            C Offline
            c.savur
            wrote on 31 May 2016, 18:47 last edited by
            #5

            @M4RZB4Ni

            You may want to see this example

            http://doc.qt.io/qt-5/qtwidgets-dialogs-configdialog-example.html

            1 Reply Last reply
            0

            1/5

            31 May 2016, 17:35

            • Login

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