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. When i have more than one QLabel in QWidget - only one is showing
Forum Updated to NodeBB v4.3 + New Features

When i have more than one QLabel in QWidget - only one is showing

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.5k 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.
  • moominekM Offline
    moominekM Offline
    moominek
    wrote on last edited by
    #1

    Hello
    When I add to QWidget (QGraphics scene on widget) more than one QLabel:

    ...
    scene = new QGraphicsScene(this);
    
    QGraphicsView * graphicsView = new QGraphicsView(scene);
    QBoxLayout * layout = new QVBoxLayout;
    ...
    
    for(int i=0; i<=10; ++i){
            QLabel * label = new QLabel(QString::number((10-i)%10));
            label->setStyleSheet(sheetstyle);
            label->setAlignment(Qt::AlignCenter);
            label->setFont(font);
            label->setGeometry(0, (i * labelHeight) ,labelWidth,labelHeight * 0.8);
            label->show();
            scene->addWidget(label);
        }
    
    ...
    layout->addWidget(graphicsView);
    setLayout(layout);
    

    Only one is visible . When durring animation (or when i use scroll bar) visible QLabel becomes invisible, another one QLabel
    appears.

    Widget have't got any set flags or atributes. Main Windows type is popup.

    Maybe anyone know what is wrong?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @moominek said:
      Hi
      Are you 100% sure they dont overlap?

      is labelHeight some ok value?
      try with move()

      1 Reply Last reply
      0
      • moominekM Offline
        moominekM Offline
        moominek
        wrote on last edited by moominek
        #3

        Yes i'm sure.
        I wan't to make Widget which lookslike this:

        0
        9
        8
        7
        6
        5
        4
        3
        2
        1
        0
        

        And it is creating (it is embded in QWidget with lowe height. I Want to have only one digit, and when state change I want move widget up or down to show other digit). When I animate my widget next digit is showing, after previous digit goes out view. But in my project digit should change smoothly.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Your code works for a normal widget.

          I wonder if addWidget(label); does use x,y of Geometry.
          I think it stacks them all once inserted.

          have you inserted 2 labels with very different pos and seen that it does
          indeed use x,y ?

          1 Reply Last reply
          0
          • moominekM Offline
            moominekM Offline
            moominek
            wrote on last edited by
            #5

            I add :

            qDebug() << "x:" <<label->x() << "y:" << label->y();
            

            and the results:

            x: 0 y: 0
            x: 0 y: 270
            x: 0 y: 540
            x: 0 y: 810
            x: 0 y: 1080
            x: 0 y: 1350
            x: 0 y: 1620
            x: 0 y: 1890
            x: 0 y: 2160
            x: 0 y: 2430
            x: 0 y: 2700
            

            I think is everything ok with x and y.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              hi
              I tested in Diagramscene sample and your code does show
              as expected
              http://postimg.org/image/ddr5urlf5/

              1 Reply Last reply
              0
              • moominekM Offline
                moominekM Offline
                moominek
                wrote on last edited by
                #7

                Ok. I have previous version of this program. And it's works. I don't know why :).

                Is only one diffrence. In my code i don't set parent when I add Widget to another Widget.

                May this influence the problem appears?

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  well I would assume setWidget would set the parent else
                  the Labels would be free floating.

                  But in this sample here, you add directly to scene so if u in the real code

                  • add to another widget then yes it might be.
                    try to call setParent on each label and see if it works then.
                  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