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. How to setEnabled(false) ?

How to setEnabled(false) ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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
    Meugiwara
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        1

        • Login

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