Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Qt/Qt Designer (Version 3.x) GUI questions
Forum Updated to NodeBB v4.3 + New Features

Qt/Qt Designer (Version 3.x) GUI questions

Scheduled Pinned Locked Moved Brainstorm
28 Posts 5 Posters 13.7k 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.
  • Q Offline
    Q Offline
    qt-newbie107
    wrote on last edited by
    #16

    Loladiro,

    I took your code and made some mods to it so that it would compile without errors using Qt 4.2.1. Here they are:

    1. mylabel.h

    @
    #ifndef MYLABEL_H
    #define MYLABEL_H

    #include <QLabel>

    //in mylabel.h
    class MyLabel : public QLabel
    {
    Q_OBJECT

    public slots:
    void setFileName(QString name)
    {
    setPixmap(name);
    }
    };

    #endif
    @

    1. Also, made some mods to main.cpp:

    @
    #include <QApplication>
    #include <QSignalMapper>
    #include <QPushButton>

    #include "mylabel.h"

    //in main.cpp
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

     QSignalMapper mapper;
     MyLabel label;
     QPushButton b1;
     QPushButton b2;
     mapper.setMapping(&b1,"gif1.gif");
     mapper.setMapping(&b2,"gif2.gif");
     QObject::connect(&b1,SIGNAL(clicked()),&mapper,SLOT(map()));
     QObject::connect(&b2,SIGNAL(clicked()),&mapper,SLOT(map()));
     QObject::connect(&mapper,SIGNAL(mapped(QString)),&label,SLOT(setFileName(QString)));
     label.show();
    
     return app.exec();
    

    }
    @

    When I run the executable, I get a very small window. When I expand it, I am getting a pure grey background: No pushbuttons. No gifs displayed. Nothing.

    Please help.

    Thanks,
    Qt-Newbie

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #17

      I though you would incorporate it into existing code, my mistake:
      @
      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

       QWidget mainWidget;
      
       QSignalMapper mapper;
       MyLabel label;
       QPushButton b1(&mainWidget);
       QPushButton b2(&mainWidget);
       mapper.setMapping(&b2,"gif2.gif");
       mapper.setMapping(&b2,"gif2.gif");
       QObject::connect(&b1,SIGNAL(clicked()),&mapper,SLOT(map()));
       QObject::connect(&b2,SIGNAL(clicked()),&mapper,SLOT(map()));
       QObject::connect(&mapper,SIGNAL(mapped(QString)),&label,SLOT(setFileName(QString)));
      
       QVBoxLayout verticalLayout(&mainWidget);
       verticalLayout.addWidget(&label);
       QHBoxLayout horizontalLayout(&mainWidget);
       horizontalLayout.addWidget(&b1);
       horizontalLayout.addWidget(&b2);
       verticalLayout.addLayout(&horizontalLayout);
      
       mainWidget.show();
      
       return app.exec();
      

      }
      @

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #18

        You're never calling show() on your buttons.

        While, ideally, all the widgets should be children of another parent widget with a layout, etc., the code you have is sufficient to test out the mechanics of the QSignalMapper, but you currently need to show each widget.

        Edit: Nevermind. You figured it out. :-)

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #19

          @
          Edit: Nevermind. You figured it out. :-)
          @
          I would have included all that for the beginning, but I thought he wanted an example usage, not a complete app.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #20

            No worries. It all seems to have sorted itself out :-)

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qt-newbie107
              wrote on last edited by
              #21

              All,

              The example worked ! Thank you all for your notes.

              I have further questions:

              1. The worked out example indicates the ability to do the sequence:
                Push a Button --> signal/slot --> map a GIFn file --> display GIFn in mylabel

              What I would need to do is:

              a) Push a Button --> Query an interface --> Receive reply from interface --> signal/slot/map a GIF file based on interface reply --> display GIF in mylabel

              Where would I put the stub code to accomplish this ? Is there a Qt 4 solution ?

              b) Can I make system call functions in Qt 4 ? I am talking a "system()" type call to a Python 2.4 script I have already developed.

              Please reply.

              Thank you all,

              Qt-Newbie

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #22

                [quote]
                Push a Button —> Query an interface —> Receive reply from interface —> signal/slot/map a GIF file based on interface reply —> display GIF in mylabel

                Where would I put the stub code to accomplish this ? Is there a Qt 4 solution ?
                [/quote]
                A little bit trickier, but like:
                @

                class MyMainWindow
                {
                QLabel *label;

                public slots:
                void buttonClicked(int nr)
                {
                label->setPixmap(queryInterface(nr));
                }
                };

                //and the button creation like:
                for(int i = 0; i < maxButtons; ++i)
                {
                QPushButton *b = new QPushButton(this);
                mapper.setMapping(b,i);
                connect(b,SIGNAL(clicked()),&mapper,SLOT(map()));
                myLayout->addWidget(b);
                }

                @

                Depending on how long it takes to query the interface, you might want to have a separate, slot to set the image that is being called once the interface is done.

                [quote]
                b) Can I make system call functions in Qt 4 ? I am talking a “system()” type call to a Python 2.4 script I have already developed.
                [/quote]

                Have a look at "QProcess":http://doc.qt.nokia.com/latest/qprocess.html

                DISCLAIMER: The code shown is a use case example and neither complete nor intended for direct use in an application.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qt-newbie107
                  wrote on last edited by
                  #23

                  All,

                  How do I place text inside the pushbuttons ? I do not see any methods with the QPushButton class. Is it inherited ?

                  Please reply.

                  Thanks,
                  Qt-Newbie

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    loladiro
                    wrote on last edited by
                    #24

                    Yes, from "QAbstractButton":http://doc.qt.nokia.com/latest/qabstractbutton.html

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      qt-newbie107
                      wrote on last edited by
                      #25

                      Loladiro,

                      Thanks. I got the button text labels via the QAbstractButton class.

                      Please explain where "queryInterface(nr)" is defined. I am a bit confused. Do I need to write a class/method for this ? Is it a wrapper ?

                      Thanks,
                      Qt-Newbie

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mlong
                        wrote on last edited by
                        #26

                        Qt-newbie, please start a new thread for new topics.

                        Software Engineer
                        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #27

                          I splitted it and used this title :
                          Can you please recommend a textbook on Qt4

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            loladiro
                            wrote on last edited by
                            #28

                            [quote author="qt-newbie" date="1313106592"]Loladiro,

                            Thanks. I got the button text labels via the QAbstractButton class.

                            Please explain where "queryInterface(nr)" is defined. I am a bit confused. Do I need to write a class/method for this ? Is it a wrapper ?

                            Thanks,
                            Qt-Newbie[/quote]

                            Since I have no idea what kind of interface you have I just put it there to indicate where you have to query your interface.

                            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