[SOLVED] Selecting a label



  • Hi guys,
    .
    I am new to Qt and I am trying to develop an user interface with it.
    .
    I have two questions:
    .
    1- Is it possible to add widgets without using vertical/ horizontal layouts? I want to add some labels in runtime inside a scroll area for exemple, but the parent widget (the scroll area) has no children so I could use any layout.
    .
    2- Is it possible to select a label? I mean, I have several labels, each one showing a QPicture/ QPixmap and I want to select one of them to display its picture in high resolution. Is it possible?
    .
    Thank you all in advance,

    Gabe



  • You can position widgets manually but really sounds like you want a QGraphicsView and QGraphicsScene.



  • Hello! Thank you very much for you reply!
    .
    Actually I already solved my problem, but now I am with a new and more difficult one:
    .
    I created a list of a random number o buttons, where each button is created by the user by pressing a main button, called "New button". Now, I need to add some funcionality to these new created buttons.
    .

    I created a class AddButton as:
    @
    class AddButton{

    publilc:
    AddButton() {}
    AddButton(QString, QIcon);
    QPushButton returnButton(void) {return *newButton;};
    QIcon returnIcon(void) {return *img;}

    protected:
    QString name;
    QIcon img;
    QPushButton
    newButton;
    };
    @
    .
    Then, I created a list, using std::list to store every new button the user creates. Like std::list<AddButton> btnList;
    .
    Now, I need that these buttons do something. Every button will have the same functionality, displaying its name on a text field, for exemple.
    .
    Does anyone here have any idea of how can I do that?



  • For your first post I don't see why you don't want to use the layouts. They are dynamic and much easier than the alternative.

    For the buttons you need to connect the button signals you are interested to the main class

    @
    class Parent_Widget : QWidget
    {
    Q_OBJECT
    ...
    public slots:
    void Button_Clicked(void);
    };

    QPushButton* AddButtonClass::returnButton(Parent_Widget *parent)
    {
    QPushButton *new_button = new QPushButton(parent);

    connect(new_button,SIGNAL(clicked(void)),parent,SLOT(Button_Clicked(void)));

    return new_button;
    }

    @

    I don't think you need a class for the purpose of creating buttons; I would think it should be part of the parent class.



  • Hello! Thank you for your reply! Now this part of the code is working great! Thank you!



  • Wrong place! Sorry!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.