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. Display a Personal Object (Draw a Circle) on QScrollArea & QGridLayOut
Qt 6.11 is out! See what's new in the release blog

Display a Personal Object (Draw a Circle) on QScrollArea & QGridLayOut

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 2 Posters 6.6k 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.
  • yczoY Offline
    yczoY Offline
    yczo
    wrote on last edited by
    #5

    for(qint8 i= 0; i < 15;i++){
    circle[i] = new ampel(this,1333,768);
    circle[i]->show();

    this does not work :-(

    mrjjM 1 Reply Last reply
    1
    • yczoY yczo

      for(qint8 i= 0; i < 15;i++){
      circle[i] = new ampel(this,1333,768);
      circle[i]->show();

      this does not work :-(

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #6

      @yczo
      ok, also try the resize(100,100)!

      well u need to find out if its due not being paint or what the heck is going on.

      Make small sample and insert you ampel there as
      the only widget and see if u can make it show.

      Normally its not issue to make it show. so its something really simple.

      1 Reply Last reply
      0
      • yczoY Offline
        yczoY Offline
        yczo
        wrote on last edited by
        #7
            circle[i] = new ampel(this,1333,768);
            circle[i]->show();
            circle[i]->resize(100,100);
        

        don't works.
        It could not be because the object handles another layer?

        regards

        mrjjM 1 Reply Last reply
        0
        • yczoY yczo
              circle[i] = new ampel(this,1333,768);
              circle[i]->show();
              circle[i]->resize(100,100);
          

          don't works.
          It could not be because the object handles another layer?

          regards

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #8

          @yczo

          Impossible to say.
          Maybe u cover it or maybe ur paint dont work.
          You should test your custom widget in a test project where
          NOTHING else could disturbed it.

          That way u know if it can even paint itself.

          ampel * circle = new ampel(this,1333,768);
          circle->show();
          circle->resize(100,100);

          should be enough in test project.

          Code do look fine as was as i can overview it.

          yczoY 1 Reply Last reply
          1
          • mrjjM mrjj

            @yczo

            Impossible to say.
            Maybe u cover it or maybe ur paint dont work.
            You should test your custom widget in a test project where
            NOTHING else could disturbed it.

            That way u know if it can even paint itself.

            ampel * circle = new ampel(this,1333,768);
            circle->show();
            circle->resize(100,100);

            should be enough in test project.

            Code do look fine as was as i can overview it.

            yczoY Offline
            yczoY Offline
            yczo
            wrote on last edited by yczo
            #9

            @mrjj The next code works, but not into the QScrollArea, and invalidate it, the focus is blocked. (i have changed the object, for send the radius ).

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)

            {
                ui->setupUi(this);
                setFixedSize(1333,768);
            
            
                const qint8 rad = 15;
                ampel *circle0[15];
                for(qint8 i= 0; i < 15;i++){  //<-------here show 15 circles
                    circle0[i] = new ampel(this,1333,768,rad);
               //     circle[i]->show(); //not necesary
               //     circle[i]->resize(100,100); //resize, do not work
                    circle0[i]->updatePos(rad*i,rad*i);
                }
            
                QGridLayout *grid = new QGridLayout();
            
                ampel *circle[15];
                QLineEdit *channel[15], *timeOut[15], *canID[15];
            
                for(qint8 i= 0; i < 15;i++){
                    circle[i] = new ampel(this,1333,768,5); //<--------here do not show nothing
                    circle[i]->show();
                    circle[i]->resize(100,100);
                    channel[i] = new QLineEdit();
                    timeOut[i] = new QLineEdit();
                    canID[i] = new QLineEdit();
            
            
                    grid->addWidget(circle[i],i,0);
                    grid->addWidget(channel[i],i,1);
                    grid->addWidget(timeOut[i],i,2);
                    grid->addWidget(canID[i],i,3);
                }
            
                ui->scrollContents->setLayout(grid);
              //  channel[2]->setText("prueba");
              //  timeOut[3]->setText("timeout");
            }
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #10

              hi
              Ok, so now they show?
              what u mean by focus is blocked?

              yczoY 1 Reply Last reply
              0
              • mrjjM mrjj

                hi
                Ok, so now they show?
                what u mean by focus is blocked?

                yczoY Offline
                yczoY Offline
                yczo
                wrote on last edited by yczo
                #11

                @mrjj That I can not scroll down the slider of QScrollArea.
                The circles shown outside QScroll area, but not inside

                mrjjM 1 Reply Last reply
                0
                • yczoY yczo

                  @mrjj That I can not scroll down the slider of QScrollArea.
                  The circles shown outside QScroll area, but not inside

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #12

                  @yczo said:

                  grid->addWidget(circle[i],i,0);

                  but you add to grid?
                  That grid is in scrollarea?
                  How can it be outside?
                  The other objects u add, they are inside?

                  yczoY 2 Replies Last reply
                  0
                  • mrjjM mrjj

                    @yczo said:

                    grid->addWidget(circle[i],i,0);

                    but you add to grid?
                    That grid is in scrollarea?
                    How can it be outside?
                    The other objects u add, they are inside?

                    yczoY Offline
                    yczoY Offline
                    yczo
                    wrote on last edited by
                    #13

                    @mrjj Yes, but don't shows. i think that the problem come from the way of generate the circle with absolute coordinates:

                    dc.drawEllipse(x,y,rad,rad);
                    

                    x,y (absolute)

                    but i don't know another way, to make it.
                    Is There another method?

                    Regards

                    mrjjM 1 Reply Last reply
                    0
                    • yczoY yczo

                      @mrjj Yes, but don't shows. i think that the problem come from the way of generate the circle with absolute coordinates:

                      dc.drawEllipse(x,y,rad,rad);
                      

                      x,y (absolute)

                      but i don't know another way, to make it.
                      Is There another method?

                      Regards

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #14

                      @yczo
                      Hi it cant be absolute!
                      It will be relative to your self so the area
                      is 0,0, width, height !

                      You draw inside. so u cannot ! use global x,y
                      you must move whole object! and it draws internal from 0,0

                      so
                      dc.drawEllipse(x,y,rad,rad);
                      x,y can never be more than width / height :)

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @yczo said:

                        grid->addWidget(circle[i],i,0);

                        but you add to grid?
                        That grid is in scrollarea?
                        How can it be outside?
                        The other objects u add, they are inside?

                        yczoY Offline
                        yczoY Offline
                        yczo
                        wrote on last edited by
                        #15

                        @mrjj
                        We have a small misunderstanding, the new program draw twice, 15 circles out QScroll and should draw another 15 inside, but the last, don't make, just draw the first 15 created on mainwindow

                        Greetings.

                        mrjjM 1 Reply Last reply
                        0
                        • yczoY yczo

                          @mrjj
                          We have a small misunderstanding, the new program draw twice, 15 circles out QScroll and should draw another 15 inside, but the last, don't make, just draw the first 15 created on mainwindow

                          Greetings.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          ok so it does draw and all is as you except ?
                          except the last is not inside the layout/scrollbox?

                          Do u make these really big ?
                          new ampel(this,1333,768,5);

                          is it 1333 x 768 ???

                          yczoY 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            ok so it does draw and all is as you except ?
                            except the last is not inside the layout/scrollbox?

                            Do u make these really big ?
                            new ampel(this,1333,768,5);

                            is it 1333 x 768 ???

                            yczoY Offline
                            yczoY Offline
                            yczo
                            wrote on last edited by
                            #17

                            @mrjj 1333x768 is the size of layout where is permitted to draw

                            mrjjM 1 Reply Last reply
                            0
                            • yczoY yczo

                              @mrjj 1333x768 is the size of layout where is permitted to draw

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #18

                              @yczo

                              but if u must draw that big, it means u make the
                              Widget so big ?

                              How big are the circle widgets?????

                              You can not draw outside the widget.

                              yczoY 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @yczo

                                but if u must draw that big, it means u make the
                                Widget so big ?

                                How big are the circle widgets?????

                                You can not draw outside the widget.

                                yczoY Offline
                                yczoY Offline
                                yczo
                                wrote on last edited by
                                #19

                                @mrjj Here is a hint: http://www.scriptscoop2.com/t/787129021050/qt-draw-inside-qscrollarea-in-a-qdialog.html

                                but i don't know how to:

                                Create another class which inherits QWidget. Override the paintEvent() method and to the painting you mention. Then, add the widget to the scroll area in your dialog.
                                
                                MyDialog::MyDialog()
                                {
                                  QScrollArea *pScrl = new QScrollArea(this);
                                  pScrl->setWidget(new MyWidget(pScrl));
                                  ... // use a layout to put the scroll area in the dialog
                                }
                                
                                To really make it useful you will need to resize the MyWidget instance to the size of the circle that you want to draw.
                                

                                Please can anybody help me? With a example?

                                Greetings

                                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