Skip to content
QtWS25 Call for Papers
  • 0 Votes
    9 Posts
    1k Views
    A

    @KenAppleby-0
    I have an extremely stupid proof of concept that sort of does what I describe in the initial message, it's extremely rough and should not be considered a good idea by anybody, but here goes:

    from PyQt6.QtWidgets import QWidget, QPushButton, QGridLayout, QSizePolicy, QApplication from PyQt6.QtGui import QColor, QPalette from PyQt6.QtCore import Qt class BorderWidget(QWidget): def __init__(self, widget_id, side, layout=None, row=None, column=None): super(BorderWidget, self).__init__() self.widget_id = widget_id self.side = side self.layout = layout self.row = row self.column = column pal = self.palette() pal.setColor(QPalette.ColorRole.Window, QColor('white')) self.setAutoFillBackground(True) self.setPalette(pal) self.pressed = False def mousePressEvent(self, event): super(BorderWidget, self).mousePressEvent(event) print(f"Clicked on {self.side} border of widget {self.widget_id}") print(f"self.press is {self.pressed}") self.pressed = True self.last_x = event.globalPosition().x() self.last_y = event.globalPosition().y() def mouseReleaseEvent(self, event): self.pressed = False def mouseMoveEvent(self, event): if self.pressed and self.layout is not None: dx = event.globalPosition().x() - self.last_x self.last_x = event.globalPosition().x() dy = event.globalPosition().y() - self.last_y self.last_y = event.globalPosition().y() if dx != 0: if self.side in ['right', 'left']: new_stretch = max(1, self.layout.columnStretch(self.column) - dx) self.layout.setColumnStretch(self.column, int(new_stretch)) elif self.side in ['bottom', 'top']: new_stretch = max(1, self.layout.rowStretch(self.row) - dy) self.layout.setRowStretch(self.row, int(new_stretch)) class DraggableWrapper(QWidget): def __init__(self, widget, widget_id, main_layout, row, column): super(DraggableWrapper, self).__init__() self.layout = QGridLayout(self) self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.border_top = BorderWidget(widget_id, 'top', main_layout, row, column) self.border_bottom = BorderWidget(widget_id, 'bottom', main_layout, row + 1, column) self.border_left = BorderWidget(widget_id, 'left', main_layout, row, column) self.border_right = BorderWidget(widget_id, 'right', main_layout, row, column + 1) self.border_top_left_horizontal = BorderWidget(widget_id, 'topleft', main_layout, column) self.border_top_right_horizontal = BorderWidget(widget_id, 'topright', main_layout, column) self.border_bottom_left_horizontal = BorderWidget(widget_id, 'bottomleft', main_layout, column) self.border_bottom_right_horizontal = BorderWidget(widget_id, 'bottomright', main_layout, column) self.layout.addWidget(widget, 1, 1) self.layout.addWidget(self.border_top, 0, 1) self.layout.addWidget(self.border_bottom, 2, 1) self.layout.addWidget(self.border_left, 0, 0, 3, 1) # cover the corners self.layout.addWidget(self.border_right, 0, 2, 3, 1) # cover the corners self.layout.addWidget(self.border_top_left_horizontal, 0, 0) self.layout.addWidget(self.border_top_right_horizontal, 0, 2) self.layout.addWidget(self.border_bottom_left_horizontal, 2, 0) self.layout.addWidget(self.border_bottom_right_horizontal, 2, 2) border_width = 10 self.border_top.setFixedHeight(border_width) self.border_bottom.setFixedHeight(border_width) self.border_left.setFixedWidth(border_width) self.border_right.setFixedWidth(border_width) # apply size restrictions to corner border widgets to form L-shaped corners self.border_top_left_horizontal.setFixedSize(border_width, border_width) self.border_top_right_horizontal.setFixedSize(border_width, border_width) self.border_bottom_left_horizontal.setFixedSize(border_width, border_width) self.border_bottom_right_horizontal.setFixedSize(border_width, border_width) # Apply size policies self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) class MainWindow(QWidget): def __init__(self): super().__init__() layout = QGridLayout(self) layout.setSpacing(0) default_stretch = 300 layout.setRowStretch(0, default_stretch) layout.setRowStretch(1, default_stretch) layout.setColumnStretch(0, default_stretch) layout.setColumnStretch(1, default_stretch) widget1 = QPushButton("Button 1") wrapper1 = DraggableWrapper(widget1, '1', layout, 0, 0) widget2 = QPushButton("Button 2") wrapper2 = DraggableWrapper(widget2, '2', layout, 0, 1) widget3 = QPushButton("Button 3") wrapper3 = DraggableWrapper(widget3, '3', layout, 1, 0) widget4 = QPushButton("Button 4") wrapper4 = DraggableWrapper(widget4, '4', layout, 1, 1) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(wrapper1, 0, 0) layout.addWidget(wrapper2, 0, 1) layout.addWidget(wrapper3, 1, 0) layout.addWidget(wrapper4, 1, 1) if __name__ == '__main__': app = QApplication([]) mainWin = MainWindow() mainWin.setMinimumSize(800, 800) mainWin.show() app.exec()
  • 0 Votes
    4 Posts
    273 Views
    SGaistS

    Qt integrates very well with OpenGL so I am unsure what you think you would be missing ?

    That said, another possible way to do what you want could be the Graphics View Framework.

  • 0 Votes
    5 Posts
    819 Views
    N

    Hi @LeLev,

    I tried your solution. Its showing the image. That is fine.
    Now if i have more elements then its filling in the same space.
    I need to scroll thorough the screen to see the elements.
    How to do that ? How should I use Flickable in this case.

    Note: For example: If the screen layout is 500x500, and each element size id 50x50,
    then i should only see 16 elements initially. I have to scroll down on the screen to see the remaining elements.

  • 0 Votes
    1 Posts
    409 Views
    No one has replied
  • 0 Votes
    8 Posts
    3k Views
    R

    @jonb Yes, that is the document to which I was referring. Thank you for posting the link!

  • 0 Votes
    4 Posts
    9k Views
    L

    First of all I am glad that you found a solution you're happy with.
    Nevertheless, I still recommend to use GridView. On the one hand, it probably reduces your amount of code, on the other hand, and most importantly, it's much more readable to you and every other developer, who might want to help you or needs some Inspiration, because he has the same problems as you have.

    To your question:

    On of the key features of Qml is property binding. So let's say you have

    import QtQuick.Controls 2.3 ApplicationWindow { id: root width: 600; height: 600 visible: true Rectangle { width: parent.width/2; height: parent.height/2 color: "blue" } MouseArea { anchors.fill: parent onClicked: { root.width -= 10; root.height += 10; } } }

    If you click the applicationWindow its width will be decreased by 10 and its height increased by 10. At the same time the rectangle's width will be decreased by 5 and its height increased by 5. That's because its size depends on the size of the applicationWindow and will be changed automatically.

    Same applies to your case. If the model changes its size, your ListView should notice this and update the list.

    Just in case you don't know (or if it's working in your case, didn't know how your model looks like) you can do:
    model: yourModelName.length
    or if it's a List of Arrays/Vectors
    model: yourModelName[index].length

    Index should be available through the outer ListView if I did understand you correctly.

    ListView { model: yourModel.length delegate: ListView { model: yourModel[index].length } }

    Probably there is no need to write an "getLengthOfDataVector" function, if you intended to do it like this. But maybe I missed something as I don't know how you model looks like exactly.

  • 0 Votes
    19 Posts
    5k Views
    C

    @SeeLook Looks like the model can be a QAbstructListModel which is exactly what I use...
    It's interesting, I'll try this out.

    Other problems are the insert and remove function that GridView supports, as well as the shouldfechmore and fetchmore functions. (implemented inQAbstructListModel)

  • 2 Votes
    2 Posts
    1k Views
    ?

    Thank you for sharing!

  • 0 Votes
    6 Posts
    2k Views
    M

    I have posted suggestion about adding such positioner to QtQuick:
    https://bugreports.qt.io/browse/QTBUG-57549

  • 0 Votes
    2 Posts
    2k Views
    RajeeshRaveendranR

    Hi,

    there are 2 possible cases:

    If you are sure that void DistanceThread::run() exit after first iteration then you are setting "flagforbreak" or "diststop" in between. So could you please check the slots of those signals which you are emitting? (May be the flag set from there).

    DistanceThread::run() is still executing but your conditions (i saw complex nested "If"s there :) ) may not meet anytime.(Hope U will debug it ensure that.

    Regards,
    Rajeesh Raveendran

  • 0 Votes
    2 Posts
    1k Views
    FerdlF

    I think i got it... sometimes you don't see the tree in the wood...

    Is just change inside the Grid....

    ButtonMenu { width: columnbutton.w; height: columnbutton.h; operation: buttonUserTEXTA; onClicked: {menuuser.state = "STATE A" } }

    so easy, and I can remove the if-else stuff inside the ButtonMenu.qml...

    I think its SOLVED!!

  • 0 Votes
    12 Posts
    6k Views
    Joel BodenmannJ

    @russQt I was digging hard but unfortunately I have no positive news for you. Sorry about that.

  • 0 Votes
    8 Posts
    6k Views
    C

    @Mark81 Even in JavaScript you have two models, you just don't typically think of it that way: model 1: the database, model 2: the results on the client side.

    Here, you have two models: 1 - the database, 2 - the QML side.

    So what you need to do is create a paginated model using LIMIT/OFFSET queries.

  • 0 Votes
    12 Posts
    3k 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

  • 0 Votes
    5 Posts
    2k Views
    oblivioncthO

    @alex_malyu

    Thank you for the ideas. I will keep this in mind.

  • 0 Votes
    1 Posts
    548 Views
    No one has replied
  • 0 Votes
    3 Posts
    1k Views
    D

    Thanks for your reply.

  • 0 Votes
    1 Posts
    683 Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied