Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TextLabel and Buttons
Forum Updated to NodeBB v4.3 + New Features

TextLabel and Buttons

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zheka777
    wrote on last edited by
    #1

    Hello all,

    i have a Button (checkable) and a TextLabel ("checked" and "uncheked").
    When thu Button is checked I want that the TextLabel "cheked" appears and when the Button is unchecked, the TextLabel "uncheked" appears.

    I tryed it like this:
    @MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    ui->label_1->hide();
    ui->label_2->hide();
    
    if (ui->pushButton->isChecked()) {
        ui->label1-show();
    }
    else
    ui->label_2->show();
    

    @

    But it doesnt work.
    Can someone help me please?

    Hochschule Kempten

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

      What does not work? What does it do?

      Why don't you connect the triggered signal of the button to your slot where you just change the text of the label or of course you can hide/show different labels as well.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tilsitt
        wrote on last edited by
        #3

        Hi,

        Without using "signal/slot mechanism":http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html, you will always have label1 showed. You should do something like this instead:
        @
        connect(ui->pushButton, SIGNAL(toggled(bool)), this, SLOT(updateLabel(bool)));

        void MainWindow::updateLabel(bool _is_checked)
        {
        if(_is_checked)
        {
        ui->label->setText(tr("Checked"));
        }
        else
        {
        ui->label->setText(tr("Unchecked"));
        }
        }
        @

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zheka777
          wrote on last edited by
          #4

          EDIT:
          @tilsitt Thank you very much. It works :)

          [quote author="butterface" date="1383732104"]What does not work? What does it do?

          Why don't you connect the triggered signal of the button to your slot where you just change the text of the label or of course you can hide/show different labels as well.[/quote]

          for Example:

          When Button cheked:
          !http://s14.directupload.net/images/131106/oix7bshd.jpg(Bild)!

          When uncheked:
          !http://s1.directupload.net/images/131106/6zuqc43n.jpg(picture)!

          @tilsitt
          Thanks, I would try it now.

          Hochschule Kempten

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved