Skip to content
  • 0 Votes
    7 Posts
    170 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
    2 Posts
    183 Views
    Christian EhrlicherC

    There is no leak. How do you measure? Please provide a minimal, compileable example of the problem.

  • 0 Votes
    4 Posts
    253 Views
    H

    I find this docs in Microsoft, but they use C#. I don't know If Qt can do the same as them?

    Microsoft Title bar

    9035dd12-20d8-40d1-8733-563f3ae7d060-image.png

  • 0 Votes
    5 Posts
    305 Views
    G

    @Abderrahmene_Rayene smart!

  • 0 Votes
    2 Posts
    203 Views
    Abderrahmene_RayeneA

    Hi,

    Please provide the following information:

    Qt kit you are using. Qt Creator version. OS, and if Linux, what desktop environment?

    I tested that stylesheet on Fedora KDE spin, using Qt 5.15.2/6.2.4/6.6.1, Qt Creator 12, and this MRE:

    int main(int argc, char *argv[]) { QApplication a(argc, argv); QTabWidget t; t.setStyleSheet(R"(QTabWidget::pane { border: 3px solid rgb(68, 76, 94); } /*======TAB*========*/ QTabBar::tab { /*color: rgb(68, 76, 94);*/ border: 2px solid rgb(68, 76, 94); } QTabWidget::tab-bar:top { top: 3px; } QTabWidget::tab-bar:bottom { bottom: 2px; } QTabWidget::tab-bar:left { right: 2px; } QTabWidget::tab-bar:right { left: 2px; } QTabBar::tab:left:last, QTabBar::tab:right:last, QTabBar::tab:left:only-one, QTabBar::tab:right:only-one { margin-bottom: 0px; } QTabBar::tab:first { border-top-left-radius: 10px; border-top-right-radius: 10px; } QTabBar::tab:last { border-top-left-radius: 10px; border-top-right-radius: 10px; } QTabBar::tab:middle { border-top-left-radius: 10px; border-top-right-radius: 10px; } QTabBar::tab:top, QTabBar::tab:bottom { min-width: 8ex; margin-right: -1px; padding: 5px 10px 5px 10px; } QTabBar::tab:top:last, QTabBar::tab:bottom:last, QTabBar::tab:top:only-one, QTabBar::tab:bottom:only-one { margin-right: 0; } QTabBar::tab:left, QTabBar::tab:right { min-height: 8ex; margin-bottom: -1px; padding: 10px 5px 10px 5px; } /*TAB:SELECTED*/ QTabBar::tab:selected { background: white; color: rgb(68, 76, 94); border-color: rgb(68, 76, 94); border-bottom-color: transparent; margin-top: 0; } QTabBar::tab:top:selected { border-bottom-color: none; } QTabBar::tab:bottom:selected { border-top-color: none; } QTabBar::tab:left:selected { border-left-color: none; } QTabBar::tab:right:selected { border-right-color: none; } /*TAB !SELECTED*/ QTabBar::tab:!selected { color: white; background-color: rgb(68, 76, 94); border-color: rgb(68, 76, 94); border-width: 3px; } QTabBar::tab:top:!selected { margin-top: 4px; } QTabBar::tab:bottom:!selected { margin-bottom: 3px; } QTabBar::tab:left:!selected { margin-right: 3px; } QTabBar::tab:right:!selected { margin-left: 3px; })"); t.addTab(new QWidget, "Variable fisicas"); t.addTab(new QWidget, "Variable fisiologicas"); t.addTab(new QWidget, "Unidad de Control de Agua"); t.show(); return a.exec(); }

    and I get this:

    QTabWidgetStyleSheetIsNormal.gif

    Which looks normal.

    I also tried it on in Qt Designer, just slapped a QTabWidget on a QMainWindow and applied the stylesheet on it, and got this:

    QTabWidgetStyleSheetIsNormalInQtDesigner.gif

    I also tried to apply the stylesheet on the main window, and the QApplication just to be sure, but same result.

  • 0 Votes
    2 Posts
    191 Views
    Christian EhrlicherC

    The style always wins as written here: https://doc.qt.io/qt-6/stylesheet.html#overview

    "Style sheets are applied on top of the current widget style,"

  • 0 Votes
    11 Posts
    830 Views
    SGaistS

    Hi,

    System styles such as those from Windows and macOS ignore certain hints and draw controls as expected for these platforms. Qt follows the platform user interface guidelines closely to ensure that applications looks as expected.

  • 0 Votes
    13 Posts
    812 Views
    G

    @Narutoblaze Since I recently burned my feathers, I strongly advise you not to try to go against how the automatisms and things in general have been built, especially if it's just because you're used to doing it in a certain way.

    Use the signals available, use installEventFilter, avoid complications just to look cool, simplify the goals.

    You'll do the cool stuff in the future, after you get used to it.

  • 0 Votes
    8 Posts
    429 Views
    jsulmJ

    @Narutoblaze Please read again what @JonB wrote. Especially what he copied from Qt documentation...

  • 0 Votes
    12 Posts
    771 Views
    M

    AS @JonB said,
    Python is a dynamic language, C++ is not.
    So, you need to make an explicit cast to retreive the type of object you want.
    If you expect e->source() to return a QTabWidget, you need to do:

    QTabWidget* tabWidget=qobject_cast<QTabWidget*>(e->source()); if(tabWidget) // is a tab widget ? ( // indeed it is ) else { // is not }
  • 0 Votes
    2 Posts
    1k Views
    Abderrahmene_RayeneA

    From the Qt documentation (qt6), QTabWidget::setCornerWidget: says:

    Note: Corner widgets are designed for North and South tab positions; other orientations are known to not work properly.

    That means they do work, but are messy to and inconvenient to use.

    Here's a way to use QTabWidget corner widget on the side:

    As already noted in the question, setting a corner widget while tabs position is West or East, causes a small gap before the tabs without anything appearing there.

    But if you set QTabWidget's corner widget minimum size, it will appear, which solves a problem but causes another, because now I need to calculate that size myself, or make room for my corner widget.

    Here's an MRE that I used to try and figure how to get that empty corner size:

    QTabWidget *t = new QTabWidget(); //I needed the stacked widget so I can use its geometry to calculate the empty corner size QStackedWidget *stack_widget = t->findChild<QStackedWidget*>("qt_tabwidget_stackedwidget"); t->setMinimumSize(800,600); t->addTab(new QWidget(),"Tab1"); t->addTab(new QWidget(),"Tab2"); t->addTab(new QWidget(),"Tab3"); t->addTab(new QWidget(),"Tab4"); t->setTabPosition(QTabWidget::TabPosition::West); QToolButton *button1 = new QToolButton(); button1->setIcon(QIcon(":/icons/collapse.png")); t->setCornerWidget(button1,Qt::TopLeftCorner); t->show(); //width is equal to where the stack widget starts (x coordinate) //height is equal to where the tab bar starts (y coordinate) //I subtracted 1 from stackwidget's x because it simply looked better t->cornerWidget(Qt::TopLeftCorner)->setMinimumSize(stack_widget->geometry().x()-1, t->tabBar()->geometry().y()); //checking related widgets geometries /*qDebug()<<"cornerWidget geo"<<t->cornerWidget(Qt::TopLeftCorner)->geometry(); qDebug()<<"tabBar rect"<<t->tabBar()->tabRect(0); qDebug()<<"tabBar geo"<<t->tabBar()->geometry(); qDebug()<<"stackwidget geo"<<sw->geometry();*/

    Here's how it looks, I used a custom icon:

    Corner widget appeared

    If you need more space for the corner widget, you'll need to move the tab bar, because corner widget will cover it, you can do that using stylesheet. See this: Qt Style Sheets Examples: Customizing QTabWidget and QTabBar.

    Here's an example of stylesheet:

    t->setStyleSheet("QTabWidget::tab-bar " "{" "top: 50px;" /* push down by 50px */ "}");

    Here's how it looks with that being the only addition and change to my MRE:

    Extended tab widget corner widget

    Suggestion: QTabWidget::paintEvent might be a better solution.

  • 0 Votes
    5 Posts
    2k Views
    SGaistS

    Thanks for the detailed deep dive !

  • 0 Votes
    5 Posts
    527 Views
    B

    I see. Thank you.

  • 0 Votes
    8 Posts
    1k Views
    F

    @ChrisW67 What if I want to resize the tabs but index-based?

    Similar to a web browser, I want to enable a button/tab-like interface. The first tab should, if possible, display only the icon and the last being a new tab option will display a varied interface.

  • 0 Votes
    1 Posts
    165 Views
    No one has replied
  • 0 Votes
    1 Posts
    268 Views
    No one has replied
  • 0 Votes
    7 Posts
    2k Views
    msyasakM

    Thank you @JonB, "currentChanged.connect" is worked.

  • 0 Votes
    7 Posts
    767 Views
    D

    @jsulm Thank you

  • 0 Votes
    8 Posts
    2k Views
    D

    @Ketan__Patel__0011 said in QTabWidget style the top buttons...:

    @Dariusz said in QTabWidget style the top buttons...:

    FUSION

    If you want to set "FUSION" Style for your application

    add this line in your main function

    qApp->setStyle(QStyleFactory::create("Fusion"));

    Hey
    Yeah that's the style im using. I'm trying to reproduce in css the button style now with black outline, then the white "ping" of border and gradient background.

    Are there any more style presets I can download? I know there is also windows/windowvista ones but... more ?
    There seem to be a large preset/plugin system build for styles but I dont see any on web available for use... mhmm ?

  • 0 Votes
    2 Posts
    386 Views
    jsulmJ

    @moslehuddin You should be more precise when asking a question. What exactly are you asking? How to get data from a database? How to show it? Both? How to use QScrollArea?
    Qt SQL: https://doc-snapshots.qt.io/qt5-5.14/qtsql-index.html
    How to show the data: https://doc.qt.io/qt-5/qsqltablemodel.html and https://doc.qt.io/qt-5/qtableview.html
    How to use QScrollArea: https://doc.qt.io/qt-5/qscrollarea.html