Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to setEnabled(false) ?

    General and Desktop
    3
    3
    1692
    Loading More Posts
    • 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
      Meugiwara last edited by

      Hello !

      My problem is the next : I have two QListWidget and the first is setEnabled(true) and the second is setEnabled(false). If at least I select one item of the first QListWidget and the first QListWidget is not empty, the second QListWidget becomes setEnabled(true), but if the first QListWidget is empty and no item is selected, I can't setEnabled(false) the second QListWidget. May someone has the solution ? Here is my code :

      SecondWindow::SecondWindow(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::SecondWindow)
      {
          ui->setupUi(this);
          ui->button_1->setIcon(QIcon(":/Images/Images/Haut.png"));
          ui->button_2->setIcon(QIcon(":/Images/Images/Bas.png"));
          ui->button_5->setIcon(QIcon(":/Images/Images/Haut.png"));
          ui->button_6->setIcon(QIcon(":/Images/Images/Bas.png"));
      
          connect(ui->button_1, SIGNAL(clicked()), this, SLOT(UpForLeft()));
          connect(ui->button_2, SIGNAL(clicked()), this, SLOT(DownForLeft()));
          connect(ui->button_3, SIGNAL(clicked()), this, SLOT(DeleteForLeft()));
          connect(ui->button_4, SIGNAL(clicked()), this, SLOT(AddForLeft()));
          connect(ui->button_9, SIGNAL(clicked()), this, SLOT(ShowThirdWindow()));
          connect(ui->button_10, SIGNAL(clicked()), this, SLOT(close()));
          connect(ui->table_1, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(EditForLeft(QListWidgetItem *)));
          connect(ui->table_1, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(SelectInList(QListWidgetItem *)));
      }
      
      SecondWindow::~SecondWindow()
      {
          delete ui;
      }
      
      void    SecondWindow::ShowThirdWindow()
      {
          ThirdWindow *window = new ThirdWindow;
      
          window->setWindowTitle("HELLO");
          window->setFixedSize(820, 440);
          window->show();
      }
      
      void    SecondWindow::SelectInList(QListWidgetItem *item)
      {
          if ((ui->table_1->count() != 0) && (item->isSelected()))
              ui->table_2->setEnabled(true);
          else
              ui->table_2->setEnabled(false);
      }
      

      Thank you !

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi
        If first List is empty, there is nothing to select and hence no signal is fired and
        your SelectInList is never called.

        So when there is nothing to click on, what action / what would user do
        to also Enable the second even when first is empty.

        Click on the empty whole list could do it ?

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          These are two separate things to handle. You should rather handle that state separately: i.e. disable the second QListWidget when you remove the last item from the first one. And then handle the selection enabled using QListWidget's selection model selectionChanged signal.

          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 Reply Quote 1
          • First post
            Last post