Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How to toggle the text on a button

    General and Desktop
    1
    2
    738
    Loading More Posts
    • 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.
    • T
      technovelist last edited by

      In the book, "C++ GUI Programming with Qt4 (second edition)", at the end of the implementation of the sort extension dialog, the statement is made that it is easy to change the text on a button so that it shows "Advanced >>>" when only a basic dialog is visible and "Advanced <<<" when the extension is shown. I have tried to change the text on the button from "More" to "Less" when the extension is shown and back to "More" when only the basic dialog is shown, but have been unable to get this to work

      I have managed to get control to go to my code by connecting the "clicked" signal to my code, but for some reason my code is called more than once for each click, which screws up my algorithm that is trying to toggle the displayed text. I have also tried "released" and "pressed" signals, to no avail.

      Here is my code. I would appreciate any tips on how to get this to work, seeing that it is so "easy".
      Thank you.

      @
      #include <QtGui>

      #include "sortdialog.h"

      SortDialog::SortDialog(QWidget *parent)
      : QDialog(parent)
      {
      setupUi(this);

      secondaryGroupBox->hide();
      tertiaryGroupBox->hide();
      layout()->setSizeConstraint((QLayout::SetFixedSize));
      
      setColumnRange('A','Z');
      
      connect(moreButton,SIGNAL(clicked()),this,SLOT(on_moreButton_clicked()));
      

      }

      void SortDialog::setColumnRange(QChar first, QChar last)
      {
      primaryColumnCombo->clear();
      secondaryColumnCombo->clear();
      tertiaryColumnCombo->clear();

      secondaryColumnCombo->addItem(tr("None"));
      tertiaryColumnCombo->addItem(tr("None"));
      
      primaryColumnCombo->setMinimumSize(
              secondaryColumnCombo->sizeHint());
      
      QChar ch = first;
      while (ch <= last) {
          primaryColumnCombo->addItem(QString(ch));
          secondaryColumnCombo->addItem(QString(ch));
          tertiaryColumnCombo->addItem(QString(ch));
          ch = ch.unicode() + 1;
      }
      

      }

      void SortDialog::on_moreButton_clicked()
      {
      if (moreButton->text() == tr("More"))
      moreButton->setText(tr("Less"));
      else
      moreButton->setText(tr("More"));
      }

      @

      1 Reply Last reply Reply Quote 0
      • T
        technovelist last edited by

        Never mind; I figured out that I should be using the toggled signal instead. Now it works.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post