Skip to content
  • 0 Votes
    4 Posts
    247 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
    291 Views
    G

    @Abderrahmene_Rayene smart!

  • 0 Votes
    2 Posts
    181 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
    1 Posts
    116 Views
    No one has replied
  • 0 Votes
    11 Posts
    807 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
    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
    1 Posts
    163 Views
    No one has replied
  • 0 Votes
    2 Posts
    309 Views
    BDC_PatrickB

    Anyone?
    T_T

  • 0 Votes
    1 Posts
    305 Views
    No one has replied
  • 0 Votes
    8 Posts
    2k Views
    mrjjM

    Hi
    I did not find any other way to gain access to the tab bar.

  • 0 Votes
    11 Posts
    3k Views
    Y

    Thank You @SGaist and @AndyS. I am able to get QToolButton of QTabBar by applying Fusion style.

    I applied Fusion Style By:

    #include "mainwindow.h" #include <QTimer> #include <QtGlobal> #include <QFile> #include <QLocale> #include <QSplashScreen> #include <QGuiApplication> #include <qstylefactory.h> int main(int argc, char *argv[]) { QLocale::setDefault(QLocale::system()); QApplication a(argc, argv); a.setStyle(QStyleFactory::create("Fusion")); MainWindow w; w.showMaximized(); return a.exec(); }
  • 0 Votes
    3 Posts
    8k Views
    pauleddP

    Thank you! I see you specified height and width manually. That works so far. I will use that.

  • 0 Votes
    3 Posts
    2k Views
    P

    VRonin, thanks for looking at that. I'm seeing that -- call to d->makeVisible(index); -- also in Qt 5.5.1. As is apparent from the code, that "ensure visible" DOES work as long as SOME OTHER tab is currently current -- i.e. in the call to QTabBar::setCurrentIndex(int). Conversely, it doesn't work if the new current index is already current.

    I regard this as a Qt bug. I've run into this a few times -- arguably overzealous optimizations in Qt code. Side effects like this cannot always be skipped. Here is the current Qt 5.5.1 code:

    void QTabBar::setCurrentIndex(int index) { Q_D(QTabBar); if (d->dragInProgress && d->pressedIndex != -1) return; int oldIndex = d->currentIndex; if (d->validIndex(index) && d->currentIndex != index) { d->currentIndex = index; update(); d->makeVisible(index); d->tabList[index].lastTab = oldIndex; if (oldIndex >= 0 && oldIndex < count()) d->layoutTab(oldIndex); d->layoutTab(index); #ifndef QT_NO_ACCESSIBILITY ... ... ... #endif emit currentChanged(index); } }

    A workaround I've tested is as follows. If the QTabBar's current tab IS the one you want current (but may have been scrolled out of view by the user), you need to first call QTabBar::setCurrentIndex(int) with some other tab, and then call it again with the desired tab.

    I did this (not generalized here, specific to my context) ...

    // Note [Phil, RW 7.1, Qt 5.5.1, 5-2017]: Because of a bug in QTabBar:: // setCurrentIndex(int), the QTabBar isn't scrolled to the specified // index IF that index is already the QTabBar's current index. // SEE forum post: https://forum.qt.io/topic/79200/ if ((_objTabBar->currentIndex() == objTabInx) && (_objTabBar->count() > 1)) { _objTabBar->setCurrentIndex ((objTabInx > 0) ? objTabInx-1 : 1); } _objTabBar->setCurrentIndex (objTabInx); installSimObj (refObj);
  • 0 Votes
    6 Posts
    2k Views
    SGaistS

    Right, that's the best solution if you are using a QTabWidget.

  • 0 Votes
    5 Posts
    2k Views
    S

    @raven-worx
    ah right, couldn't be easier. :)
    Maybe I'll come up with another solution for my issue like subclassing and repainting the tabbar. For now that'll do the trick.
    Cheers

  • 0 Votes
    14 Posts
    12k Views
    mrjjM

    Hi
    Sounds ok to me. another signal based version of widgetAt :)

  • 0 Votes
    12 Posts
    5k Views
    mrjjM

    super :)
    its easy to overlook stuff in own code :)

  • 0 Votes
    6 Posts
    9k Views
    A

    Had a similar Issue. Was able to find a solution. Below is a generic PyQt5 example that solves the problem using right click.

    import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * class Tabs(QTabWidget): def __init__(self, parent): super().__init__(parent) self.parent = parent self.setAcceptDrops(True) self.tabBar = self.tabBar() self.tabBar.setMouseTracking(True) self.indexTab = None self.setMovable(True) self.addTab(QWidget(self), 'Tab One') self.addTab(QWidget(self), 'Tab Two') def mouseMoveEvent(self, e): if e.buttons() != Qt.RightButton: return globalPos = self.mapToGlobal(e.pos()) tabBar = self.tabBar posInTab = tabBar.mapFromGlobal(globalPos) self.indexTab = tabBar.tabAt(e.pos()) tabRect = tabBar.tabRect(self.indexTab) pixmap = QPixmap(tabRect.size()) tabBar.render(pixmap,QPoint(),QRegion(tabRect)) mimeData = QMimeData() drag = QDrag(tabBar) drag.setMimeData(mimeData) drag.setPixmap(pixmap) cursor = QCursor(Qt.OpenHandCursor) drag.setHotSpot(e.pos() - posInTab) drag.setDragCursor(cursor.pixmap(),Qt.MoveAction) dropAction = drag.exec_(Qt.MoveAction) def dragEnterEvent(self, e): e.accept() if e.source().parentWidget() != self: return print(self.indexOf(self.widget(self.indexTab))) self.parent.TABINDEX = self.indexOf(self.widget(self.indexTab)) def dragLeaveEvent(self,e): e.accept() def dropEvent(self, e): print(self.parent.TABINDEX) if e.source().parentWidget() == self: return e.setDropAction(Qt.MoveAction) e.accept() counter = self.count() if counter == 0: self.addTab(e.source().parentWidget().widget(self.parent.TABINDEX),e.source().tabText(self.parent.TABINDEX)) else: self.insertTab(counter + 1 ,e.source().parentWidget().widget(self.parent.TABINDEX),e.source().tabText(self.parent.TABINDEX)) class Window(QWidget): def __init__(self): super().__init__() self.TABINDEX = 0 tabWidgetOne = Tabs(self) tabWidgetTwo = Tabs(self) layout = QHBoxLayout() self.moveWidget = None layout.addWidget(tabWidgetOne) layout.addWidget(tabWidgetTwo) self.setLayout(layout) if __name__ == '__main__': app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
  • 0 Votes
    6 Posts
    4k Views
    freddy311082F

    @Paul-Colby
    Yes paaul, it doesn't work for me neither

    any other advise ?

    regards

  • 0 Votes
    6 Posts
    2k Views
    Christian EhrlicherC

    @Chris-Kawa Maybe you can ping @AndyS again so we can take a look on it. I had no time for it to think about an own patch.