You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

kagen

Beginner

  • "kagen" is male
  • "kagen" started this thread

Posts: 28

Location: South Africa

Occupation: Developer using QT

  • Send private message

1

Wednesday, January 12th 2005, 7:54am

Signals From anohter class

The idea: I created my own widget that is a checkbox with the text on the left. It consits of a label and a text box with no text.
It inherits from qwidget because both the the checkbox and the label are widgets.
But now I want to use the signals from checkbox so that my checkbox can accept all the interaction that a normal check box can.

Heres the header and the constructor:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef QLEFTTEXTCHECKBOX_H
#define QLEFTTEXTCHECKBOX_H

#include <qvariant.h>
#include <qwidget.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qbutton.h>

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;


class QLeftTextCheckBox : public QWidget
{
    Q_OBJECT
public:
    QLeftTextCheckBox( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~QLeftTextCheckBox();
     
     QLabel* text;
     QCheckBox* box;
     
     void setText(QString& s);
     void setText(QString s);
     
     void setAlignment(int);
     
     QCheckBox* returnBox();
     
protected:

public slots:
     void setGeometry(int x, int y, int w, int h);
     void setGeometry(const QRect &);

protected slots:
     virtual void languageChange();
    

};

#endif 

QLeftTextCheckBox::QLeftTextCheckBox( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
	setName( "LeftTextCheckBox" );
        
    text = new QLabel("Text",this);
    text->setGeometry(25,15,35,13);
    box = new QCheckBox("",this);
    box->setGeometry(60,16,20,15);
    languageChange();
    resize( QSize(200, 180).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
}


If you can either tell me how to get the signals from QChackBox or to write my own signals working the same as those of checkbox.

I have also tried to get them from QButton but with no luck

K
CODE
Carefully
Ordered
Device
Events

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

2

Wednesday, January 12th 2005, 9:07am

Quoted

It inherits from qwidget because both the the checkbox and the label are widgets.

Well, this issue is subjective, but I would say this is a reason NOT to inherit from QWidget.
I would make it a subclass of QCheckBox, and make the QLabel a memeber.
This way you have the QCheckBox signals with no work at all.

Quoted

If you can either tell me how to get the signals from QChackBox or to write my own signals working the same as those of checkbox.

Well, as it is, cou can write slots connected to the QCheckBox signals, in which you can emit signals (pass on) parallel signals.
I never tried it, but it could be you dont even need slot, but just:
connect(chekcBox,SIGANAL(the_signal()),this,SIGNAL(passOnSignal()));

If you are doing this because you need a right to left look because your gui is in right to left language, read the QStyle documentation, you can have the whole gui set to right to left orientation, with out the need to construct each widget by your self.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

kagen

Beginner

  • "kagen" is male
  • "kagen" started this thread

Posts: 28

Location: South Africa

Occupation: Developer using QT

  • Send private message

3

Wednesday, January 12th 2005, 10:25am

Already followed that road

I have tried to inherit from QCheckBox-it compiles fine but when I want to execeute the bin file it starts and then nothing ever apears on the screen.

Ie just changing QWidget to QCheckBox and sending the correct variables hence the reason why i did it this way. Have tried the signal passing along-don't know exactly how to do it tried your idea but then when you toggle the checkbox nothing happens.

Currently it works by passing the checkbox member through returnCheckBox() and then using the signals of the returned pointer, but its not the best way of doing ti.
CODE
Carefully
Ordered
Device
Events

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

4

Wednesday, January 12th 2005, 10:31am

Quoted

I have tried to inherit from QCheckBox-it compiles fine but when I want to execeute the bin file it starts and then nothing ever apears on the screen.

That doesn't mean the apraich is bad, probably you are doing something wrong in the code it self.
Post it, so we can help.

Quoted

Have tried the signal passing along-don't know exactly how to do it

the connect() statement that i sugested is legal, you can use that to pass on signals.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"