Qt Forum

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

    Call for Presentations - Qt World Summit

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

    Brainstorm
    5
    28
    10478
    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.
    • Q
      qt-newbie107 last edited by

      Greetings,

      I am very new to Qt/Qt Designer (version 3 on a RHEL 5.x). Please bare with me.

      I am trying to put together a simple GUI on QT Designer as follows:

      1. A bottom row of pushbuttons (selected from QT Designer)
      2. A "textlabel" rectangle (also selected from QT Designer) on top of the pusbuttons. I would like to "paste/insert" a pre-crafted GIF/PNG pre-image file inside the textlabel in 2)

      What I am looking to do with QT Designer (or manually coded through QT development package) is to select a different GIF file to insert in the rectangle 2) above for each of the pushbuttons I have. That is:

      1. Insert GIF1 into 2) when push-button 1 is pressed
      2. ...
        N) Insert GIFN into 2) when push-button N is pressed.

      Please reply.

      Thank you all,
      Qt-Newbie

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        have a look at "QSignalMapper":http://doc.qt.nokia.com/4.7/qsignalmapper.html#details

        It exists also for Qt3 but in the old docs you don't have this example.

        use @setIcon@ to set the GIF and you can use smart QString to find the right one.

        If you have more specific questions you're welcome to ask ;)

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 0
        • Q
          qt-newbie107 last edited by

          Eddy,

          Thanks for your reply and your offer. I will likely have further questions on signal mapping depending on how I fare.

          Do I use "uic" tool in the QT package to convert QT Designer's .ui file (for my basic GUI layout with the widgets) to C++ source code ? Any insights on the ease of development between QT Designer and hand-coding ?

          Thanks,

          QT-Newbie

          1 Reply Last reply Reply Quote 0
          • Q
            qt-newbie107 last edited by

            Greetings,

            Is the "setIcon" method in "QAction Class" or is it from another QT Class API ?

            Thanks,
            Qt-Newbie

            1 Reply Last reply Reply Quote 0
            • E
              Eddy last edited by

              [quote author="qt-newbie" date="1312387258"]Greetings,

              Is the "setIcon" method in "QAction Class" or is it from another QT Class API ?

              Thanks,
              Qt-Newbie
              [/quote]

              Sorry I didn't make myself clear. It's a method of QPushButton.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                [quote author="qt-newbie" date="1312386007"]
                Do I use "uic" tool in the QT package to convert QT Designer's .ui file (for my basic GUI layout with the widgets) to C++ source code ? Any insights on the ease of development between QT Designer and hand-coding ?[/quote]

                Yes that's the way it works, both with Qt3 and Qt4.

                If you put the names of the ui files to the FORMS variable in your .pro file, this step will be executed automatically for you. You will have to include the resulting header file, that contains the implementation in some of your headers.

                See the "Qt Designer 3.3":http://doc.qt.nokia.com/3.3/designer-manual.html documentation for the gory details.

                Just another question: Are you forced to use Qt3 by any means? If not, you should strongly consider to start your development with Qt4. Qt3 is not maintained actively any more and the sources for help will decrease over time. And of course you save yourself the work of converting later on :-)

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply Reply Quote 0
                • E
                  Eddy last edited by

                  [quote author="qt-newbie" date="1312386007"]Eddy,
                  Do I use "uic" tool in the QT package to convert QT Designer's .ui file (for my basic GUI layout with the widgets) to C++ source code ? Any insights on the ease of development between QT Designer and hand-coding ?
                  Thanks,
                  QT-Newbie[/quote]

                  Have a look in the "Qt Designer manual":http://doc.qt.nokia.com/3.3/designer-manual-6.html.

                  Also, please use Qt instead of QT(= QuickTime) and you will make even more friends here ;)

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply Reply Quote 0
                  • Q
                    qt-newbie107 last edited by

                    Volker,

                    Thanks for your reply.

                    I am using QT3.3 as it is installed by default in RHEL 5.4. I am not sure if QT4 is supported in it. As my project is in a hyper-drive schedule (and I started a few days ago), I am trying to minimize risk by sticking to the defaults.

                    Question to all: Is there any simple example from QT3 I can use which shows the use of QSignalMapper (with the setIcon method in QPushButton) as pointed out by Eddy ?

                    Any simple example (or links) are welcomed.

                    Thanks,

                    • QT-Newbie
                    1 Reply Last reply Reply Quote 0
                    • E
                      Eddy last edited by

                      The link to the QSignalmapper docs I gave you has an example that is similar to what you want. I suggest you start with it and then use the setIcon method later on.

                      You can ask specific questions as you proceed. If you show us some code of what you accomplished it's easier to help.

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply Reply Quote 0
                      • G
                        goetz last edited by

                        Then please switch to Qt4. You can always get the sources from the "Qt download pages":http://qt.nokia.com/downloads/downloads#qt-lib (get the as tar.gz) and compile Qt yourself, it's only a matter of a

                        @
                        ./configure
                        make
                        sudo make install
                        @

                        combo.

                        Qt3 is outdated and definitely not recommended for new projects - only use it if you absolutely must. Qt5 is in a rise already!

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply Reply Quote 0
                        • Q
                          qt-newbie107 last edited by

                          All,

                          I have made the switch to Qt 4. However, I have scoured over Qt , TrollTech and Nokia pages, examples and web search resources to to attempt finding a Qt4 example tied to my application and I simply cannot find one.

                          I am in urgent need of a simple example showing the following (hand-code C++ would be OK):

                          1. A widget (on top) where a GIF file can be loaded and displayed within it (the GIF files are externally crafted, so that's not a problem)

                          2. Two push-buttons (below the widget in 1) ) horizontally placed. Each push-button loads a separate GIF:

                          • push-button 1 loads GIF # 1 in 1)
                          • push-button 2 loads GIF # 2 in 1)

                          Eddy: You mentioned using QSignalMapper in Qt 4 with setIcon and the smarts on QString to find the right GIF files. I cant' seem to locate it in the examples section of Qt 4. Can you show me a really simple example or send me the code you refer to ?

                          All: I really need your help.

                          Thank you very much,

                          Qt-Newbie

                          1 Reply Last reply Reply Quote 0
                          • E
                            Eddy last edited by

                            this is the "link":http://doc.qt.nokia.com/4.7/qsignalmapper.html#details I gave you. It still works ;)
                            I know it's not exactly what you want to do but it gives you a good start.

                            What do you have so far?

                            Qt Certified Specialist
                            www.edalsolutions.be

                            1 Reply Last reply Reply Quote 0
                            • L
                              loladiro last edited by

                              consider the following:
                              @
                              //in mylabel.h
                              class MyLabel : public QLabel
                              {
                              Q_OBJECT

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

                              //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();
                              

                              }

                              @

                              1 Reply Last reply Reply Quote 0
                              • Q
                                qt-newbie107 last edited by

                                Eddy, Loladiro,

                                Thanks very much for your replies.

                                Loladiro: I will start with your code and let you know how I fare.

                                Qt-Newbie

                                1 Reply Last reply Reply Quote 0
                                • L
                                  loladiro last edited by

                                  There was a copy&paste error in my code.
                                  I had
                                  @
                                  mapper.setMapping(&b2,"gif2.gif");
                                  @
                                  twice. It's fixed now.

                                  1 Reply Last reply Reply Quote 0
                                  • Q
                                    qt-newbie107 last edited by

                                    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 Reply Quote 0
                                    • L
                                      loladiro last edited by

                                      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 Reply Quote 0
                                      • M
                                        mlong last edited by

                                        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 Reply Quote 0
                                        • L
                                          loladiro last edited by

                                          @
                                          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 Reply Quote 0
                                          • M
                                            mlong last edited by

                                            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 Reply Quote 0
                                            • First post
                                              Last post