Skip to content
QtWS25 Last Chance
  • QLabel won't expand enough vertically

    Unsolved General and Desktop python qlabel
    3
    0 Votes
    3 Posts
    208 Views
    K
    But the window does get resized when using more text, below is a demonstration of the same window being rendered with different amounts of text in the label [image: 020ed5ed-ec29-461f-a0c6-dcadc6b44171.png] The text does resize the window dynamically but does it to a wrong size
  • 0 Votes
    4 Posts
    318 Views
    G
    For the historical record, I finally got it working. My code: ` QRect screenGeometry = QGuiApplication::primaryScreen( )->geometry( ); int x13; int x23; int y13; int y23; if( screenGeometry.width( ) < width( )) { x13 = m_image->getScrollX( ) + screenGeometry.width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * screenGeometry.width( ) / 3.0; } else { x13 = m_image->getScrollX( ) + width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * width( ) / 3.0; } if( screenGeometry.height( ) < height( )) { y13 = m_image->getScrollY( ) + screenGeometry.height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * screenGeometry.height( ) / 3.0; } else { y13 = m_image->getScrollY( ) + height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * height( ) / 3.0; } QPainter painter( this ); painter.setPen( QPen( Qt::red, 4, Qt::SolidLine, Qt::FlatCap )); painter.drawLine( 0, y13, width( ), y13 ); painter.drawLine( 0, y23, width( ), y23 ); painter.drawLine( x13, 0, x13, height( )); painter.drawLine( x23, 0, x23, height( )); } `
  • 0 Votes
    7 Posts
    431 Views
    Pl45m4P
    @herocon Ok next attempt: ui->label->setPixmap(p.scaled(ui->label->size())); Each iteration scales the pixmap to current label size and then sets the pixmap to the label. By doing this, the size of the label increases with the pixmap (because of border/frame... IIRC 1px per side by default, so 2px in total). Then you take the new label size again in the next iteration and apply this new (by 2px) increased size to the pixmap... the label gets the pixmap, grows by about 2px in height and there you have your loop where your label and consequently the whole widget grows ;-) So still no bug :) And it's exactly the behavior you would expect from the debug output. (The height increases by 2 each timer interval). When using another layout setup, the layout/other widgets might "buffer" that, so the main app window does not grow. But even there, the label itself should definitely grow when you periodically set content which has the exact same size as the outter boundings of the label. Why though?! Try (not tested): int w = ui->label->width(); int h = ui->label->height(); ui->label->setPixmap(p.scaled(w - 2, h - 2)); // or this and set the pixmap only once ui->label->setScaledContents(true); Because a label with w=500, h=500 for example, can't display a pixmap with w=500, h=500. If you set a pixmap with the same size as the label itself, it will start to grow.
  • 0 Votes
    11 Posts
    3k Views
    JonBJ
    @Emrecp I believe @SGaist is telling you that you cannot guarantee that a widget with a stylesheet will look identical to one you construct with coded style attributes. As soon as you place a stylesheet on a widget you are (potentially) losing some styles which are inbuilt, so it may differ. I suggested earlier you remove the weight stuff in your example and see whether just with the font in "normal" it does or does not look identical using the same font in both code and stylesheet. If you are coding inside paintEvent() then, as you say, you cannot use stylesheet. You can only set the attributes on a QFont as you have done. I don't know whether you can go through the sources of Qt to discover just what a current style like Fusion does.
  • How include "qfont" in "qlabel" ??

    Solved General and Desktop qfont qlabel
    5
    0 Votes
    5 Posts
    661 Views
    jsulmJ
    @timob256 said in How include "qfont" in "qlabel" ??: I did not understand which command to write to make it work Open documentation for setFont: https://doc.qt.io/qt-6/qwidget.html#font-prop As you can clearly see setFont does not take a pointer to QFont, but you're trying to give it a pointer. This is basic C++ knowledge. Change to: ui->label->setFont(*font); Or, even better, don't declare font as pointer...
  • 0 Votes
    4 Posts
    624 Views
    S
    Hi all, I finally managed to find out what was the problem. The fix is the following @@ -26,7 +26,7 @@ void MainWindow::mousePressEvent(QMouseEvent* event) // If a QLabel contains the mouse pointer, then this is the QLabel that was selected QList<QLabel*> qLabelList = ui->videoStreamsFrame->findChildren<QLabel*>(); foreach(QLabel *l, qLabelList) { - QPoint mappedMousePosition = l->mapFromGlobal(mousePosition); + QPoint mappedMousePosition = l->mapToParent(l->mapFromGlobal(mousePosition)); if (l->geometry().contains(mappedMousePosition)) { rubberBand = new QRubberBand(QRubberBand::Rectangle, l); rubberBand->setGeometry(l->rect()); So, the mapFromGlobal() is translating the global coordinates to widget coordinates and the geometry(), where we use in order to check if the mouse coordinates are contained in the label, has the coordinates relative to the parent widget. So, we need to map the mouse coordinates to the parent widget, hence the function mapToParent(). Kind regards, Stavros
  • How to refer to labels created in a for loop?

    Unsolved General and Desktop qlabel loop object name
    6
    0 Votes
    6 Posts
    945 Views
    JonBJ
    @BigBen Store them in a container yourself as you create them: QList<QLabel *> labels; for (int i = 0; i < 10; i++) { QLabel *label = new QLabel; someLayout->addWidget(label); labels.append(label); } Assign them an objectName for future reference to recall an individual one: QList<QLabel *> labels; for (int i = 0; i < 10; i++) { QLabel *label = new QLabel; label->setObjectName(QString("label_%1").arg(i)); someLayout->addWidget(label); } QLabel *label_2 = someParentWidget->findChild<QLabel *>("label_2"); Collect them all via findChildren(): QList<QLabel *> labels = someParentWidget->findChildren<QLabel *>();
  • 0 Votes
    5 Posts
    715 Views
    B
    I see. Thank you.
  • Drag and Drop Implementation

    Unsolved General and Desktop drag and drop qlabel icons
    9
    0 Votes
    9 Posts
    3k Views
    W
    Awesome, I will check that out, thank you very much!
  • 0 Votes
    6 Posts
    2k Views
    JKSHJ
    @new-qt_user-2022 All the best! Feel free to post new questions if you'd like further help.
  • Cout in a loop for QLabel Widgets

    Solved General and Desktop qmap loop cout label qlabel
    9
    0 Votes
    9 Posts
    1k Views
    Swati777999S
    @jsulm said in Cout in a loop for QLabel Widgets: @Swati777999 Names[ii] = new QLabel(QString("Name %1").arg(ii)); Works perfectly! Thanks.
  • How do I make a QLabel Blink?

    Unsolved General and Desktop qt6.1.2 qtimer qlabel mainwindow windows 10
    5
    0 Votes
    5 Posts
    2k Views
    JonBJ
    @DougyDrumz2 said in How do I make a QLabel Blink?: The consensus is evidently to l hide and show a QLabel Not my "consensus :) So far as I am aware, hiding can cause different layout redraw in at least some circumstances. I retain visibility but toggle foreground color to QColor(Qt::transparent) or toggle alpha color value between 255 (opaque) and 0 (transparent) on palette QPalette::setColor(QPalette::Text, colour). Also, creating multiple QTimer::singleShot()s doesn't scale very well if you want to change the number of flashes or the interval between. Or of you have multiple labels to blink and you'd like them all to be "in sync". I use one regular repeating QTimer with a "countdown" and cancellation when it reaches 0. Up to you on both of these.
  • QLabel image load

    Unsolved General and Desktop qlabel show images c++ qscrollarea
    8
    0 Votes
    8 Posts
    1k Views
    mrjjM
    @Sai-Raul ok. but Qlabels only likes pixmaps.
  • Video recording

    Unsolved General and Desktop qlabel videocapture video recording camera camera live
    2
    0 Votes
    2 Posts
    510 Views
    jsulmJ
    @Sai-Raul Start here: https://doc.qt.io/qt-5/videooverview.html
  • Image showing in QLabel

    Unsolved General and Desktop qlabel qpixmap
    4
    0 Votes
    4 Posts
    680 Views
    Christian EhrlicherC
    @Sai-Raul said in Image showing in QLabel: Already tried that And what was the outcome? Please update your code accordingly.
  • QLabels have same width regardless of text?

    Unsolved General and Desktop qlabel layout widget
    9
    0 Votes
    9 Posts
    3k Views
    H
    @eyllanesc Oh I see, it's working now. Thank you!
  • 1 Votes
    10 Posts
    5k Views
    T
    @J-Hilk Thanks for the response, I'll look into that stackoverlfow thread
  • 0 Votes
    3 Posts
    2k Views
    S
    @ChrisW67 Thanks! It work like a charm. For the reason to why I was using QLabel, well I'm mostly testing for stuffs. I'll switch it up later.
  • QLabel::setText() not responding properly

    Unsolved General and Desktop qlabel settext
    7
    0 Votes
    7 Posts
    1k Views
    S
    @JonB Thanks, this is new information for me. Actually the "QVTKWidget" was sufficing my problem to display point cloud data. For now it is working properly because I m using VTK 7.0. It seems post VTK 8.0, the QVTKOpenglWidget needs to be used.
  • 0 Votes
    1 Posts
    313 Views
    No one has replied