Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, March 2002
Toggle buttons


Message 1 in thread

Hello,

I'd like a togglable toolbutton which checks a predicate before been set to 
"on" (and remains off and appears undepressed if the predicate is false).

After seeing that QButton::setState(bool) was virtual, I figured that this 
could just be overriden in a subclass and would get run each time the state 
of the button was changed, similar to the way QListViewItem::setOpen(bool) 
gets called no matter how it's opened; that is, that internally, the state 
was only ever set through setState().  Alternatively, the same deal with 
QToolButton::setOn(bool).

However, neither seems to be the case; clicking a togglable button 
doesn't call setState() nor setOn(), unless of course you wire up the right 
signals.  But I want to intercept the click _before_ it sets the state, so 
hooking onto some signal is no good since I can't stop the signal propagating 
(let alone ensure that no other connected slots get run).

So I have two questions:

1.

Is there a good reason why either QButton::setState() or QToolButton::setOn() 
isn't used as a "bookkeeping" method like QListViewItem::setOpen()?  In fact, 
is there any reason why QButton::setState(bool) is virtual to begin with?  No 
subclass of QButton in the library seems to use it (based on a quick grep).  
Ditto with QToolButton::setOn(bool).

2.

Is there an easy way to achieve what I want?  Overriding the QWidget event 
methods is messy due to all the checks and making sure that every way of 
onning a button is caught.

Cheers.

(Running Qt Free 2.3.1)