You are not logged in.

panzar

Trainee

  • "panzar" is male
  • "panzar" started this thread

Posts: 86

Location: Skovde, Sweden.

  • Send private message

1

Friday, June 18th 2004, 3:57pm

How to create a static widget?

Hi!

I need to make a QLabel static so I can write to it from another class. How can I do this when I've created the label (and the rest of the GUI) in the designer?

Thanks a lot,

Per

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

2

Friday, June 18th 2004, 4:40pm

I am not sure what you mean by "write to it".
However, it sounds to me that you need to subclass.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

3

Friday, June 18th 2004, 4:43pm

RE: How to create a static widget?

Why should it be static? If you used Designer, all your widgets are public.

So from another class you simply use:

theClassWithQlabel->theQLabelWidget->setText( "some buzz" ) ;

If you had declared your widget protected or private, the best way would have beed, within designer, to create getter and setter methods for the widget.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

4

Friday, June 18th 2004, 4:45pm

Keep it simple :D
Subclassing is not always the solution. When other ways exist, it often better to use them, both for execution speed and preventing hierarchy bloating.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

panzar

Trainee

  • "panzar" is male
  • "panzar" started this thread

Posts: 86

Location: Skovde, Sweden.

  • Send private message

5

Friday, June 18th 2004, 5:04pm

Quoted

Originally posted by djanubis
So from another class you simply use:

theClassWithQlabel->theQLabelWidget->setText( "some buzz" ) ;


My bad, didn't realise that the designer makes all its widgets public.

This doesn't work however:

netGoDialog->runProfileLabel->setText("hoho");

Im doing this from one of the member-methods of the Process-class and I have included "netgodialog.h" in "process.cpp" (where Im trying to do this).

Did I misunderstood you? It sounds a little bit peculiar with theClassname->theQLabel.

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

6

Friday, June 18th 2004, 5:30pm

Quoted

netGoDialog->runProfileLabel->setText("hoho");

When you do this, is the Dialog created, even if not yet shown or not?

If not, the dialog has to be instanciated, so the widgets are created.

Source code

1
2
3
NetGoDialog * netGoDialog = new NetGoDialog( this, "NetGoDialog", TRUE ) ;
netGoDialog->runProfileLabel->setText("hoho");
netGoDialog->exec() ;


If the dialog is already on screen when you want to interfere with it, the simplest is:

Source code

1
QWidgetList * qApp->topLevelWidgets() ;

Then you iterate in the list to find your dialog, and bingo !
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

This post has been edited 1 times, last edit by "djanubis" (Jun 18th 2004, 5:37pm)


panzar

Trainee

  • "panzar" is male
  • "panzar" started this thread

Posts: 86

Location: Skovde, Sweden.

  • Send private message

7

Friday, June 18th 2004, 5:37pm

Thanks for your time djanubis, but I've solved it in another way.
I just passed the QLabel as an argument to the Process-constructor.

Cheers,

Per.

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

8

Friday, June 18th 2004, 5:41pm

That's another way, right 8)
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

9

Friday, June 18th 2004, 9:07pm

Quoted

Keep it simple
Subclassing is not always the solution. When other ways exist, it often better to use them, both for execution speed and preventing hierarchy bloating.


As I said, I was not sure what "wrting to it" meant.
I thought he wanted to pass some "custom" data to it - I was sure that for text he was aware of setText().
Thats why I sugested subclassing.

Cheers.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"