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

Change StackedWidget Pages With TreeWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
stackedwidgettreewidgetsignal & slot
5 Posts 2 Posters 2.3k 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.
  • M4RZB4NiM Offline
    M4RZB4NiM Offline
    M4RZB4Ni
    wrote on 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.savurC 1 Reply Last reply
    0
    • M4RZB4NiM M4RZB4Ni

      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.savurC Offline
      c.savurC Offline
      c.savur
      wrote on 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.

      M4RZB4NiM 1 Reply Last reply
      0
      • c.savurC c.savur

        @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.

        M4RZB4NiM Offline
        M4RZB4NiM Offline
        M4RZB4Ni
        wrote on last edited by M4RZB4Ni
        #3

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

        Thanks
        M4RZB4Ni

        c.savurC 2 Replies Last reply
        0
        • M4RZB4NiM M4RZB4Ni

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

          c.savurC Offline
          c.savurC Offline
          c.savur
          wrote on 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
          • M4RZB4NiM M4RZB4Ni

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

            c.savurC Offline
            c.savurC Offline
            c.savur
            wrote on 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

            • Login

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