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. How to toggle the text on a button
QtWS25 Last Chance

How to toggle the text on a button

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 886 Views
  • 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 Offline
    T Offline
    technovelist
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      technovelist
      wrote on last edited by
      #2

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

      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