Skip to content
QtWS25 Last Chance
  • 0 Votes
    1 Posts
    533 Views
    No one has replied
  • 0 Votes
    1 Posts
    272 Views
    No one has replied
  • QML Tab and State

    Unsolved QML and Qt Quick qml + js tab states
    2
    0 Votes
    2 Posts
    2k Views
    D
    Hi again, I got something working and I thought I would share how I proceeded. In my application, the active/visible Tab is selected programmatically. As stated in the original message, the content of the Tab is dependent on the result/state of an external test. That test might be completed before the Tab is made visible. So, I first defined a set of enumerators in C++, made available to my QML code by using Q_ENUM macro and used Q_PROPERTY to define a variable in C++ that can be accessed in QML. Let's refer to this variable as testResult. I also used a set of (internal) State in my QML Tab content (see original post). In the QML file defining the Tab content, I added a Component.onCompleted which is used to the internal State based on the value of testResult. Once the Tab is visible, different controls (BUTTON) are used to let the operator select different operations, repeating the execution of the test for example, setting a new value to the internal State. Using QML State allows me to take advantage of onStateChange, and consequently set the visible content of the Tab according to the internal State. Communication between C++ and QML when the value of testResult changes is achieved using an emit notification. This solution avoids exposing internal QML State values and the variable testResult to the javascript code I am using. Thanks, Daniel
  • Allow return key in tab order

    Unsolved General and Desktop tab taborder qwidget returnpressed key event
    1
    0 Votes
    1 Posts
    784 Views
    No one has replied
  • 0 Votes
    4 Posts
    5k Views
    B
    I think i've found a solution. First, i install an eventFilter in my custom editor widget B on the internal spinbox : internalSpinbox->installEventFilter(this); Then, i implement eventFilter to treat the events on the spinbox and duplicate them to the parent: bool AbstractRatioQuantitySpinbox::eventFilter(QObject *object, QEvent *event) { // cf http://stackoverflow.com/questions/12145522/why-pressing-of-tab-key-emits-only-qeventshortcutoverride-event if (event->type() == QEvent::KeyPress) { auto keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) { QApplication::postEvent( this, new QKeyEvent(keyEvent->type(), keyEvent->key(), keyEvent->modifiers())); return true; } } else if (event->type() == QEvent::FocusOut) { auto focusEvent = static_cast<QFocusEvent *>(event); QApplication::postEvent(this, new QFocusEvent(focusEvent->type(), focusEvent->reason())); return false; } return QWidget::eventFilter(object, event); }
  • Drag tabs between QTabWidgets

    Solved General and Desktop qtabwidget qtabbar tab drag drag and drop
    6
    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
    12 Posts
    4k Views
    p3c0P
    @Alper Well earlier you had Flickable which contained Grid. Then you can use Scrollbar inside Flickable. It needs Qt.labs.controls 1.0