Results 1 to 3 of 3

Thread: Problem with disabling button

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with disabling button

    Hello,

    I have a problem with disabling button. I will be very grateful if you give me any advice.

    Let’s assume that we have a dialog which displays item’s list. Dialog has Ok and Cancel buttons. I want when user clicks one of the items of the list (selecting the item) the OK button will be enabled otherwise (deselecting the item) OK button will be disabled.

    I could enable Ok button. To do this I connect void QAbstractItemView::clicked(const QModelIndex & index) signal with the slot which enables Ok button. But this signal emitted when index is valid.

    How can I disable Ok button? How I can be known that user clicks outside the item?

  2. #2
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with disabling button

    Hi hasmik!

    The solution is to use the item view's selection model. The automatic enabling/disabling of the button can be achieved with a slot which will be connected to the selection model's selectionChanged signal.
    Qt Code:
    1. MyDialog::MyDialog(QWidget* parent)
    2. : QDialog(parent)
    3. {
    4. connect(itemView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&))
    5. ,this,SLOT(onSelectionChanged()));
    6. }
    7.  
    8. MyDialog::onSelectionChanged()
    9. {
    10. btnOk->setEnabled(itemView->selectionModel()->hasSelection());
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with disabling button

    Thank you very much.

Similar Threads

  1. problem in Displaying image on push button
    By durgarao in forum Qt Tools
    Replies: 4
    Last Post: 2nd January 2009, 10:27
  2. Problem with events changing behavior of QListWidget
    By riklaunim in forum Qt Programming
    Replies: 10
    Last Post: 22nd December 2008, 19:10
  3. How can I put a button onto the qLabel?
    By dwlnet in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 09:47
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Replies: 7
    Last Post: 15th February 2006, 11:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.