Active Topics

 


Reply
Thread Tools
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
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!

Last edited by Lullen; 2010-06-17 at 00:22.
 
Posts: 35 | Thanked: 18 times | Joined on Jun 2010
#2
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.
 

The Following User Says Thank You to iHaveNoNames For This Useful Post:
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#3
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...
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#4
No one? This shouldn't be to hard
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#5
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.
 
Posts: 180 | Thanked: 76 times | Joined on May 2010
#6
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
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#7
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?
 
Reply


 
Forum Jump


All times are GMT. The time now is 20:08.