maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Setting text to a label and more (https://talk.maemo.org/showthread.php?t=56408)

Lullen 2010-06-17 00:00

Setting text to a label and more
 
I never thought I would ask this question but how to I set text to a label properly? Both of these codes just work the first time it get called.

Code:

void FoodWindow::load()
{
    QString kcal, tmp;
    QList <QString> settings;
    int remaining;
    kcal.setNum(xml->getTodaysCalories());

    settings = xml->loadSettings();
    remaining = settings.takeLast().toInt() - kcal.toInt();
    tmp.setNum(remaining);

    if(remaining >= 0)
        lblCalories->setText("You have eaten " + kcal + " kcal today (" + tmp + " left). \nYour mean kcal/day is 2800 kcal ");
    else
        lblCalories->setText("You have eaten to much today. \nYour mean kcal/day is 2800 kcal ");
}

Code:

void ExerciseWindow::loadExercise(QList<QString> name)
{
    QDBusConnection::sessionBus().send(lock);
    QList <QString> tmp;
    QList<QString> settings = xml->loadSettings();
    QString lstReps[3];
    settings.removeLast();
    SEC = settings.takeLast().toInt();
    MIN = settings.takeLast().toInt();

    currentReps = settings.takeLast();
    lstReps[2] = settings.takeLast();
    lstReps[1] = settings.takeLast();
    lstReps[0] = settings.takeLast();

    if(currentReps == "Easy")
        REPS = lstReps[0].toInt();
    else if(currentReps == "Mid")
        REPS = lstReps[1].toInt();
    else
        REPS = lstReps[2].toInt();


    SET = settings.takeLast().toInt();

    vibrateActive = false; soundActive = false;
    if(settings.takeFirst() == "1")
        vibrateActive = true;
    if(settings.takeFirst() == "1")
        soundActive = true;

    currentExercise = name.first();
    tmp = xml->openEx(currentExercise);
    tmp.removeFirst();
    currentGroup = tmp.takeFirst();

    set = SET; reps = REPS; min = MIN; sec = SEC;
    strSet.setNum(SET); strReps.setNum(REPS); strMin.setNum(MIN);  strSec.setNum(SEC);
    label->setText("");
    label->setText(currentExercise + "\n Shake when done " + strReps + " reps");
    btnShake->setEnabled(true);
    //myThread->start(QThread::NormalPriority);
}

I am able to edit the label later but not on load wich is annoying. I have printed the text using qDebug() and its correct.

I also have problem when I went from a window to a dialog. After this code is called I guess the ui is still on-top but not showing, I can push the save button again.

Code:

void NewExerciseWindow::saveExercise()
{
    QString name = txtName->text();
    QString group = btnGroup->valueText();
    QString muscle = txtMuscle->text();
    QString info = txtHowTo->toPlainText();
    if(group == "Cardio")
        xml->saveCardio(name);
    else
        xml->saveEx(name,group,muscle,info);

    QMaemo5InformationBox::information(this, "Exercise saved.",
                                                QMaemo5InformationBox::DefaultTimeout);
    this->hide();
}

Edit: Forgot two questions about QListView. How do I disable the possibility to edit in the list manually and how do I highlight a row by knowing the name?

Thanks!

iHaveNoNames 2010-06-17 00:32

Re: Setting text to a label and more
 
long time I have not practiced the c++. But in java this problem can appear if you forget to refresh / repaint the components, maybe that is the same thing, here.

Lullen 2010-06-17 08:21

Re: Setting text to a label and more
 
After trying this I feel this might be right. I did try to call update() after setting the label text but nothing happends... Because it works later when a timer wants to change the text I tried to have a button to update the text and then the text changed to the right one!

When seeing this I remember that changing to landscape/portrait mode is exactly the same. In load/constructor nothing happends but having a button for it makes it works...

Lullen 2010-06-19 23:21

Re: Setting text to a label and more
 
No one? This shouldn't be to hard :)

Joorin 2010-06-20 07:15

Re: Setting text to a label and more
 
To save CPU time, UIs are only updated when you ask for it, when the window is moved or when something else moves out of the way.

You'll have to find out how one sets a specific part of the screen as "dirty" and in need of an update. If you're using GTK+ you can do it like this
Code:

  GdkRectangle rectangle;
  rectangle.x = GTK_WIDGET(time_and_progress)->allocation.x;
  rectangle.y = GTK_WIDGET(time_and_progress)->allocation.y;
  rectangle.width = GTK_WIDGET(time_and_progress)->allocation.width;
  rectangle.height = GTK_WIDGET(time_and_progress)->allocation.height;

  gdk_window_invalidate_rect(win->window, &rectangle, TRUE);

I'm sure there are similar mechanics in Qt.

Diph 2010-06-20 09:38

Re: Setting text to a label and more
 
How do call load method?

Another thing. You don't have to clear label content before you set text:

Code:

label->setText("");
label->setText(currentExercise + "\n Shake when done " + strReps + " reps");  //Setting the text clears previous content


Lullen 2010-06-20 09:50

Re: Setting text to a label and more
 
I finally solved this last night. What I did was to overload the changeEvent function and there called update. Why do I need to do this?


All times are GMT. The time now is 11:19.

vBulletin® Version 3.8.8