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. No idea how to manage QWidget
QtWS25 Last Chance

No idea how to manage QWidget

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.1k 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.
  • L Offline
    L Offline
    l.v.p
    wrote on last edited by
    #1

    Hi Folks!

    I have two question, because I can't find the answer in documentation.

    First of all I created QWidget using Qt Wizard. In one word: normal windows application. Then I wanted to add new child window. I did it by writing it:

    @ QWidget *now = new QWidget();

    now->show();@
    

    but it's hard do design something by this way. So I created new window with Qt wizard and I added it into project. But now I have problem: how to show it, for example, after button clicked() singal?

    In Design section, on the right panel we can see all the properties of ours items. So, let's say we have only one basic window, and it's name is wnd. When I type:

    @wnd->close();@ nothing happens, compilator can't recognize the variable.

    So how I can manage QWidgets?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Via Qt Designer you create not widgets itself, but their description. You should instantiate them via new keyword. If you have created only ui file without c++ class than you can load this file via QUiLoader.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        l.v.p
        wrote on last edited by
        #3

        hmm...ok but when I created new whole project under class name "something" there are something.ui file (where I'm designing) and something.h which consist of:

        @#ifndef SOMETHING_H
        #define SOMETHING_H

        #include <QWidget>

        namespace Ui {
        class something;
        }

        class something: public QWidget
        {
        Q_OBJECT

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

        private:
        Ui::something*ui;

        private slots:
        void on_pushButton_clicked();
        };

        #endif // SOMETHING_H@

        So, according what you wrote I have class. How I can "do things" in "something" window by coding it, not designing?

        I tried

        @
        ui->something-> no help so I'm stuck
        @

        also:
        @
        ui->Ui_Something->...nothing
        @

        Any suggestions, or I'm doing it completely wrong?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Yes, you have a class. You can now instantiate it using
          @
          something somethingObj = new something;
          @
          and you will have this widget to show it. If you want to add it to another widget as its part you should pass this widget as parameter to constructor of something.

          You can access containtments of your designed widget by using ui pointer. For example if you have a label at your widget named myLabel you can access it using ui->myLabel.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            l.v.p
            wrote on last edited by
            #5

            bq. You can access containtments of your designed widget by using ui pointer. For example if you have a label at your widget named myLabel you can access it using ui->myLabel.bq.

            Yep, I know about this, but I created it like you said, and try basic things like:

            @
            something *somethingObj = new something;
            somethingObj->show();
            @
            after click, new, exactly the same windows appears.

            @
            something *somethingObj = new something;
            somethingObj->resize(10,13);
            @

            nothing happens? So I still don't know how to manage designed window by code of lines.

            Can you explain it to me again? Or recommend some documentation?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              I think that you simply forgot to include show() in second sample of code, but used it in your sources. If not, try to add this.

              Also each widget has size hints and size policies (you can read about them in assistant), they defines how widget can be resized. Maybe you have minimum size for you widget equal to current size, so it cannot be resized smaller?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                l.v.p
                wrote on last edited by
                #7

                bq. I think that you simply forgot to include show() in second sample of code, but used it in your sources. If not, try to add this.bq.

                Yes! It's working.

                Sorry Denis but still one thing is nagging me all the time, and I'm can't find proper answer in net. I should start topic from this example:

                Imagine situation: I have parent widget which consist only lineedit and button. After button click new window(widget) should appear with another lineedit and button. User is typing something in lineedit, clicking button and then child widget is destroyed and it's passing variable to the basic widget and the first lineedit.

                So? How to do that? It will be something with "coinnect" and "slot" mechanism?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #8

                  Luka: These questions of yours are pretty well covered in any introductory Qt book I have read so far. Maybe you could save some time by just grabbing a book and working through it? After all it must kill your productivity to sit and wait for answers here in the forum.

                  Or you might try some of the free tutorials available on the net? Signals and slots are really well covered there as well.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    l.v.p
                    wrote on last edited by
                    #9

                    yes, you're right Tobias, I was trying to follow the line of least resistance. My fault!

                    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