How to setEnabled(false) ?



  • 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 !


  • Qt Champions 2016

    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 ?


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.