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 show hidden item
Forum Updated to NodeBB v4.3 + New Features

How to show hidden item

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 5.5k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    I am trying to do the following:

    1. Press button
    2. progress bar pops up, showing us the battery status

    To start with, I am trying to jast have the progress bar show at the click of a button.
    After I drew my button and progress bar in the form, I used signals and slot to do the following:

    Sender Signal Receiver Slot
    pushButton toggled(bool) progressBar setVisible(bool)

    in my mainwindows.cpp I have the following:
    ui->progressBar->hide();

    I am assuming that when I click the button, the progress bar should pop up, otherwise
    it should stay hidden. This is not happening. What am I missing?

    Thanks

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nosf
      wrote on last edited by
      #2

      The bool in toggled(bool) is for QPushButton "checked" state as in if the button is checkable.

      from what you say all you need is a custom slot with a signal leading to it from the button like:

      @
      connect(pushButton, SIGNAL(clicked()), this, SLOT(ButtonClicked()));

      void YourClass::ButtonClicked() {
      if (ui->progressBar->isVisible())
      ui->progressBar->setVisible(false);
      else
      ui->progressBar->setVisible(true);
      }
      @

      If you want the progressBar however to only be visible while "holding down your mouse over the button" you can over-ride the mousePress and mouseRelease events to do the same.

      Or

      if you set the button as checkable you would then be able to use the toggled signal to get the state and hence set the progressBar visibility from it.

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        Hi, thanks for the tip. I am a complete novice in C++, so I think I am running into some problems. Here is my code,including what you suggested (the connect statement is in a different file):
        @
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QtGui>
        #include "digitalclock.h"

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        ui->progressBar->hide();
        }

        void MainWindow::ButtonClicked() {
        if (ui->progressBar->isVisible())
        ui->progressBar->setVisible(false);
        else
        ui->progressBar->setVisible(true);
        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }
        @

        This tells me that the following:

        C:\Users\menu-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\menu\mainwindow.cpp:14: error: no 'void MainWindow::ButtonClicked()' member function declared in class 'MainWindow'

        What do I need to do to fix this?

        Thanks

        [Edit: Added @ code tags; mlong]

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          Hi,
          Kindly use code formatter for your code while posting or use @ .
          For the above example u need to add a slot in mainwindow.h

          eg:
          @class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();

          private slots:
          void ButtonClicked();

          private:
          Ui::MainWindow *ui;
          };@

          or else if you have the pushButton in your designer just Right Click -- Go to Slot-- Clicked(bool)
          and then write the code for hiding or showing the component.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            Appreciarte the help. I appologize, I am new to all this hence unfamiliar with most of what you are talking about. Is formatter a tool I can use?

            I got what I wanted to do in a different way. In the Mainwindows.ui file (in graphical view), I connected the button to the progress bar so that while it is pressed the status bar shows up and when unpressed the status bar goes away. So I used two connect signals and slots statements.

            Thanks for the tips guys, I appreciate it.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              Now I need to figure out how to show actual battery status in the progress bar. I will try to use the example they have in the QT examples folder. I will be back if things dont go well.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nosf
                wrote on last edited by
                #7

                formatter is just the button you find when posting something on the forums that looks like a document with "<>" on it. It's at the top right while your creating your message.

                Simple solution is if you want to show a peice of code use @ before and after the code so it appears in a better to read way :)

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  @Ah thank you :)@

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nosf
                    wrote on last edited by
                    #9

                    lol dont use it for everything though. It's just for code hence why they're "Code tags" :)

                    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