Skip to content
  • 0 Votes
    2 Posts
    283 Views
    A

    Hi,

    Are you looking for the Video Widget Example?

  • 0 Votes
    7 Posts
    1k Views
    V

    Yes, I have mouse tracking enabled.

    Maybe my description of the issue was not very clear, sorry. When I click for the first time on the button, it does not change its style to QStyle.State_Sunken and then back to QStyle.State_Raised on release, this happens only on the every second click. Also button does not change its style on mouse hover.

    Here is a minimal example

    import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * class MyDelegate(QStyledItemDelegate): def __init__(self): super(MyDelegate, self).__init__() self.buttonRect = None def sizeHint(self, option, index): fm = QFontMetrics(option.font) return QSize(150, fm.height() * 5 + fm.leading()) def paint(self, painter, option, index): name = index.data(Qt.DisplayRole) description = index.data(Qt.UserRole + 1) btnStyle = QStyle.State(index.data(Qt.UserRole + 2)) nameFont = QFont(option.font) nameFont.setWeight(QFont.Weight.Bold) fm = QFontMetrics(nameFont) padding = fm.lineSpacing() // 2 nameRect = QRect(option.rect) nameRect.setLeft(nameRect.left() + padding) nameRect.setTop(nameRect.top() + padding) nameRect.setRight(nameRect.right() - padding) nameRect.setHeight(fm.lineSpacing()) descrRect = QRect(option.rect) descrRect.setLeft(descrRect.left() + padding) descrRect.setTop(nameRect.bottom()) descrRect.setRight(descrRect.right() - padding) descrRect.setHeight(fm.lineSpacing()) btnText = "Add" textWidth = fm.width(btnText) self.btnRect = QRect(option.rect) self.btnRect.setLeft(descrRect.right() - textWidth * 2) self.btnRect.setTop(descrRect.bottom() + padding) self.btnRect.setRight(descrRect.right() - padding) self.btnRect.setHeight(fm.lineSpacing() * 2) borderRect = QRect(option.rect.marginsRemoved(QMargins(4, 4, 4, 4))) painter.save() pen = painter.pen() if option.state & QStyle.State_MouseOver: pp = QPen(option.palette.highlight().color()) pp.setWidth(2) painter.setPen(pp) painter.drawRect(borderRect) painter.setPen(pen) painter.setFont(nameFont) elided_text = fm.elidedText(name, Qt.ElideRight, nameRect.width()) painter.drawText(nameRect, Qt.AlignLeading, elided_text) painter.setFont(option.font) fm = QFontMetrics(QFont(option.font)) elided_text = fm.elidedText(description, Qt.ElideRight, descrRect.width()) painter.drawText(descrRect, Qt.AlignLeading, elided_text) button = QStyleOptionButton() button.text = btnText button.state = btnStyle button.rect = self.btnRect QApplication.style().drawControl(QStyle.CE_PushButton, button, painter) painter.restore() def editorEvent(self, event, model, option, index): if self.btnRect.contains(event.pos()): if event.type() == QEvent.MouseButtonPress: model.setData(index, QStyle.State_Sunken, Qt.UserRole + 2) elif event.type() == QEvent.MouseButtonRelease: model.setData(index, QStyle.State_Raised, Qt.UserRole + 2) self.do_something() else: model.setData(index, QStyle.State_Enabled | QStyle.State_HasFocus, Qt.UserRole + 2) else: model.setData(index, QStyle.State_Enabled, Qt.UserRole + 2) return super(MyDelegate, self).editorEvent(event, model, option, index) def do_something(self): print("button clicked") if __name__ == "__main__": app = QApplication(sys.argv) model = QStandardItemModel() for i in range(10): item = QStandardItem() item.setData(f"Item {i}", Qt.DisplayRole) item.setData("Item description, can be very long", Qt.UserRole + 1) item.setData(QStyle.State_Enabled, Qt.UserRole + 2) model.appendRow(item) listView = QListView() listView.setMouseTracking(True) listView.setItemDelegate(MyDelegate()) listView.setModel(model) listView.show() app.exec()
  • Ayuda

    Unsolved Spanish
    3
    0 Votes
    3 Posts
    502 Views
    O

    Hola,

    Al no utilizar un thread para el calculo, tendrías que hacer algo así:

    ui.myPushButton->setDisabled(true); QApplication::processEvents(); calcularFactorial(); ui.myPushButton->setEnabled(true);

    El "processEvents" provoca un repintado de la aplicación de manera que se verán los botones deshabilitados. Si no lo haces, al ejecutarse secuencialmente, no vas a ver el cambio de estado de los botones.

  • 0 Votes
    1 Posts
    412 Views
    No one has replied
  • 0 Votes
    4 Posts
    507 Views
    JKSHJ

    @Dexter99 said in Pyqt5 help on button and grid layouts.:

    The show is okay but now I want to add it in a grid layout.

    Please show us what you've tried.

  • 0 Votes
    1 Posts
    433 Views
    No one has replied
  • 0 Votes
    21 Posts
    6k Views
    K

    @SGaist Thanx mate :) Qt rox :D

  • Data passing

    Unsolved General and Desktop
    8
    0 Votes
    8 Posts
    3k Views
    J

    @jsulm Oh. I haven't considered that. I'm definitely going to try that. I don't know why it didn't came to my mind. Thank you very much. I really appreciate your advice. I have been stuck at this problem for a week. I am glad there are people who are willing to help beginners.

  • 0 Votes
    6 Posts
    2k Views
    Pradeep KumarP

    need to check Qt classes for system settings and native look and feel,
    and of adopting those changes for App.

    Thanks,

  • Mouse PressAndHold

    Unsolved QML and Qt Quick
    2
    0 Votes
    2 Posts
    992 Views
    I

    In my understanding this is exact what onClicked does. From the online documentation:

    "A click is defined as a press followed by a release, both inside the MouseArea (pressing, moving outside the MouseArea, and then moving back inside and releasing is also considered a click)."

    MouseArea { anchors.fill: parent onClicked: console.log("released") onPressed: console.log("pressed") }
  • 0 Votes
    2 Posts
    2k Views
    S

    I create MyClass and pass 4 images to QML in main.cpp

    class.h

    #ifndef MYCLASS_H #define MYCLASS_H #include <QDebug> #include <QObject> class MyClass : public QObject { Q_OBJECT Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY pathChanged); public: explicit MyClass(QObject *parent = 0); MyClass(QString path) { m_imagePath = path; } QString imagePath(); void setImagePath(const QString & path); signals: void pathChanged(QString path); private: QString m_imagePath; }; #endif // MYCLASS_H

    main.cpp

    QApplication app(argc, argv); app.setWindowIcon(QIcon("qrc:/images/logo.ico")); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QList<QObject*> dataList; dataList.append(new MyClass("/images/images/zaglowek.png")); dataList.append(new MyClass("/images/images/pilot.png")); dataList.append(new MyClass("/images/images/uklad_jezdny.png")); dataList.append(new MyClass("/images/images/nozne_sterowanie.png")); engine.rootContext()->setContextProperty("myModel", QVariant::fromValue(dataList));

    For Now MyClass has only image path, but it will also set state (checked-unchecked) and animation (enable-disable).
    I would like to reload this QList ( with another images, states etc. ) when button ( one of three ) is clicked ( TButton.qml ).
    How to do it ? Please help.

  • 0 Votes
    4 Posts
    1k Views
    mrjjM

    @JulienD
    Np. You can style the whole application however. All controls etc
    can be controlled with style sheet.
    Just not Caption :)

  • 0 Votes
    4 Posts
    4k Views
    Z

    これで行けました。

    function Controller()
    {

    }

    Controller.prototype.FinishedPageCallback = function()
    {
    buttons.CommitButton.hide();
    }

  • 0 Votes
    6 Posts
    2k Views
    V

    Resolved.

    When i played with second usb monitor i changed first hdmi monitor modes depth to 16. Now i set 24 bits in xorg.conf and all UI is OK.

    Thanks for all.