Hm... was looking through documentation found something called QWidget::changeEvent...
Hm... was looking through documentation found something called QWidget::changeEvent...
thx Archa4 but it's not for checked stateChanged ...
Did you try the toggle signal?
http://doc.qt.nokia.com/4.7-snapshot...on.html#toggle
Thanks Rhayader , I just override void QAbstractButton::toggled ( bool checked ) [signal] but it doesn't work, btw my buttons in QButtonGroup , but as document said it works in QButtonGroup but doesn't work as i said ...
You don't need to override the signal. It's a signal. Connect it to a Slot.
http://www.qtcentre.org/faq.php?faq=qt_signalslot........... I think this will help you
i need to override for check something then i emit signal. samething actually (;, still doesn't work btw ...
edit : I typed mistakely slot there ! so this is my mistake many people confused then![]()
Last edited by nightroad; 21st March 2011 at 11:05.
You don't emit a slot.
Connect the toggled signal to a slot and then check what you have to check ?
Then include your codes in the another function and call Q_Emit, it will trigger it
Qt Code:
{ Q_OBJECT public: ~HSPushButton(); ... private: ... signals: ... void stateChanged(bool state); protected: virtual void toggled(bool checked); ... }; HSPushButton.cpp void HSPushButton::toggled(bool checked) { emit (stateChanged(checked)); }To copy to clipboard, switch view to plain text mode
so is it wrong ? I don't think so cuz i'm using escapePressed on my buttons with same method ...
I don't get what is your goal with your HSPushButton class. Can you give us more detail ?![]()
Guyz anyway thanks for your help , i'm gonna make it with my own way =) . If i use toggled directly i have to check many thing for each buttons own event so that is crapy ... anyway Thanks all ...
I might be wrong but don't you just want to see which button has been clicked in QButtonGroup?
And does not the signal buttonClicked( int id ) work for you? You can use that on the group rather than individual buttons...
I'd rather say your approach makes it crappy. We don't know what you are doing but you're certainly having an incorrect approach. If you tell us what is the ultimate goal you wish to achieve maybe we'll be able to suggest a better solution.
Yes, it is wrong. toggled() as already noted is a signal not a slot. You can't have two functions (a signal and a slot) with the same signature.
Just please tell us what you want the HSPushButton class to do what QPushButton doesn't already do.
I have many things (private variables, Painters etc... ) in HSPushButton if i use QPushButton toggled signal for each button i have to re-type these controls for each button its own event. If i override to toggled signal in my HSPushButton then emit a signal i don't need the check these conditions for each button. Totally i wanna hide these checks from programmers who will use my HSPushButton widget. thanks ...
This suggests all those things should not be part of HSPushButton but rather some external class that does what is required upon receiving some signal from the button or some other place. Using QButtonGroup might be a good idea, something like:
Qt Code:
group->setExclusive(...); group->addButton(button1, 1); group->addButton(button2, 2); group->addButton(button3, 3); connect(group, SIGNAL(buttonClicked(int)), this, SLOT(checkButton(int))); // or buttonChecked if exclusive // ... void X::checkButton(int which){ switch(which) { case 1: ... ; break; case 2: ... ; break; case 3: ... ; break; // ... } }To copy to clipboard, switch view to plain text mode
Thank you all guys ...
Bookmarks