Skip to content
QtWS25 Call for Papers
  • 0 Votes
    4 Posts
    216 Views
    Pl45m4P

    @kshegunov

    Thanks a lot :)

  • 0 Votes
    3 Posts
    2k Views
    E

    @jsulm Fortunately, I just solved it. I should not have specified the VerticalWidgetList class as the parent of the widgets added. Apparently, when you add it to the layout, the widgets added get some sort of other parent class. I still nullptr out the widget in the takeWidget() function, however, as control of it should pass to the function receiving the return value. When I got rid of setting the parent in the addWidget() and insertWidget() functions, it now works properly.

    I do wonder if I should still delete the child widget in removeWidget() and removeWidgetAt() after removing it from the layout. Or do I need to set the parent to nullptr before deleting it? When my program used clearWidgets(), which calls removeWidget(), there was no problem.

    It works now!

    This is the source code now:

    verticalwidgetlist.h

    #ifndef VERTICALWIDGETLIST_H #define VERTICALWIDGETLIST_H #include <QScrollArea> #include <QVBoxLayout> #include <QWidgetList> class VerticalWidgetList : public QScrollArea { Q_OBJECT public: explicit VerticalWidgetList(QWidget *parent = nullptr); bool addWidget(QWidget *child); void clearWidgets(); bool insertWidget(int index, QWidget *child); bool removeWidget(QWidget *child; bool removeWidgetAt(int index); QWidget *takeWidget(int index); int widgetAt(QWidget *child) const; private: QWidget *m_central; QVBoxLayout *m_layout; QWidgetList m_list; }; #endif // VERTICALWIDGETLIST_H

    verticalwidgetlist.cpp

    #include "verticalwidgetlist.h" VerticalWidgetList::VerticalWidgetList(QWidget *parent) : QScrollArea(parent) , m_central(new QWidget) , m_layout(new QVBoxLayout(m_central)) , m_list() { setWidget(m_central); setWidgetResizable(true); } bool VerticalWidgetList::addWidget(QWidget *child) { if(child == nullptr) return false; m_layout->addWidget(child); m_list.append(child); return true; } void VerticalWidgetList::clearWidgets() { while(m_list.count()) { QWidget *widget = m_list[0]; removeWidget(widget); } } bool VerticalWidgetList::insertWidget(int index, QWidget *child) { if(index < 0 || index > m_list.count()) return false; if(child == nullptr) return false; m_layout->insertWidget(index, child); m_list.insert(index, child); return true; } bool VerticalWidgetList::removeWidget(QWidget *child) { if(child == nullptr) return false; m_layout->removeWidget(child); int index = widgetAt(child); m_list.removeAt(index); delete child; return true; } bool VerticalWidgetList::removeWidgetAt(int index) { if(index < 0 || index >= m_list.count()) return false; QWidget *widget = m_list.takeAt(index); m_layout->removeWidget(widget); delete widget; return true; } QWidget *VerticalWidgetList::takeWidget(int index) { if(index < 0 || index >= m_list.count()) return nullptr; QWidget *widget = m_list.takeAt(index); m_layout->removeWidget(widget); widget->setParent(nullptr); return widget; } int VerticalWidgetList::widgetAt(QWidget *child) const { if(child == nullptr) return -1; return m_list.indexOf(child); }

    EDIT: If anyone tried the source code up until this point, in this post, try again. I was rearranging removeWidget() and removeWidgetAt(), which I realized were mismatched in terms of their parameters. It's good now!

  • 0 Votes
    6 Posts
    4k Views
    B

    @Sphinkie
    Wow, I had not noticed there is such a namespace since I'm still mainly using 5.12.
    If the constants are QColor objects as the doc says, then you should be able to use them directly like

    w->setForeground(QColorConstants::Red); w->setBackground(QColorConstants::Yellow);
  • 0 Votes
    7 Posts
    2k Views
    M

    @mrjj
    Thank you guys very much!

  • 0 Votes
    5 Posts
    2k Views
    K

    @aha_1980
    It works ! Thanks alot
    :)

  • 0 Votes
    11 Posts
    2k Views
    M

    @mrjj yes. Everything correct. Thanks for the help

  • 0 Votes
    3 Posts
    2k Views
    E

    @diredko Why passing it once using a normal function (Q_INVOKABLE) would hurt performance in your opinion? It would certainly be more efficient to have a big list in QML than use a function again and again, and such a list isn't big for modern hardware (couple of hundreds of KBytes maybe). If you can afford to have that list in C++ you should be able to afford to have it in QML, too.

    I think the biggest performance obstacle is that the system isn't real-time, QML may do garbage collection and animation isn't fluent. I recommend just testing with the most easy solution in the lowest end hardware it will be run on and deciding after that if it's enough.

  • 0 Votes
    16 Posts
    6k Views
    Ioseph12I

    @VRonin

    After some headache days I found the problem. The FilterWindow widget had set wrong the parent in children widgets, so, the right way would be :

    void FilterWindow::setUi(std::string tittle) { Frame = new QFrame(this); //Here it must be this, to set the widget itself as the parent Frame->setObjectName(QStringLiteral("Frame")); Frame->setFixedWidth(281); Frame->setFixedHeight(89); Frame->setStyleSheet(QLatin1String("QFrame\n" "{\n" " border-style: solid;\n" " border-width: 0px;\n" " border-radius: 4px;\n" " border-color: transparent;\n" "}")); Frame->setFrameShape(QFrame::StyledPanel); Frame->setFrameShadow(QFrame::Raised); Frame->setAttribute(Qt::WA_DeleteOnClose); checkBox = new QCheckBox(Frame); checkBox->setText(tittle.c_str()); checkBox->setObjectName(QStringLiteral("checkBox")); checkBox->setGeometry(QRect(0, 0, 248, 35)); checkBox->setAutoFillBackground(false); checkBox->setStyleSheet(QLatin1String("QCheckBox\n" "{\n" " background-color: rgb(128,139,143);\n" " color: white;\n" " border-radius: 4px;\n" " padding-left: 8px;\n" "}\n" "\n" "QCheckBox::indicator:unchecked {\n" " image: url(:/OptiNanoPro/uchk);\n" "}\n" "\n" "\n" "QCheckBox::indicator:checked {\n" " image: url(:/OptiNanoPro/chk);\n" "}\n" "")); checkBox->setChecked(true); ArrowBtn = new QPushButton(Frame); ArrowBtn->setObjectName(QStringLiteral("ArrowBtn")); ArrowBtn->setGeometry(QRect(246, 0, 36, 35)); ArrowBtn->setAutoFillBackground(true); QIcon icon; icon.addFile(QStringLiteral(":/OptiNanoPro/DownArrwLd"), QSize(), QIcon::Normal, QIcon::Off); ArrowBtn->setIcon(icon); ArrowBtn->setIconSize(QSize(36, 35)); ArrowBtn->setFlat(true); Table = new QTableWidget(Frame); Table->setObjectName(QStringLiteral("Table")); Table->setGeometry(QRect(0, 35, 281, 31)); Table->setStyleSheet(QLatin1String("QTableWidget\n" "{\n" " background-color: white;\n" " border-radius: 0px;\n" "}" "\n" "QCheckBox\n" "{\n" " color: white;\n" " padding-left: 8px;\n" "}\n" "\n" "QCheckBox::indicator:unchecked {\n" " image: url(:/OptiNanoPro/uchk);\n" "}\n" "\n" "QCheckBox::indicator:checked {\n" " image: url(:/OptiNanoPro/chk);\n" "}\n" "")); ResetBtn = new QPushButton(Frame); ResetBtn->setText("Reset"); ResetBtn->setObjectName(QStringLiteral("ResetBtn")); ResetBtn->setGeometry(QRect(0, 66, 169, 23)); ResetBtn->setStyleSheet(QLatin1String("QPushButton\n" "{\n" " background-color: white;\n" " border-width: 1px;\n" " border-style: solid;\n" " border-color: rgb(86,86,84);\n" " border-radius: 3px;\n" " color: rgb(86,86,84);\n" "}")); AplyBtn = new QPushButton(Frame); AplyBtn->setText("Apply"); AplyBtn->setObjectName(QStringLiteral("AplyBtn")); AplyBtn->setGeometry(QRect(169, 66, 111, 23)); AplyBtn->setStyleSheet(QLatin1String("QPushButton\n" "{\n" " background-color: white;\n" " border-width: 1px;\n" " border-style: solid;\n" " border-color: rgb(86,86,84);\n" " border-radius: 3px;\n" " color: rgb(86,86,84);\n" "}")); }
  • list-elemetns are not "paint"

    Solved QML and Qt Quick
    7
    0 Votes
    7 Posts
    1k Views
    P

    Hi Ray,

    thanks for that tip. Now i understood the way how it works.
    i already tried and it works.
    thanks both of you
    -> solved

  • 0 Votes
    2 Posts
    1k Views
    M

    @Mark81 ok, I found a way:

    QDBusInterface *iface = new QDBusInterface("your.service", "/your/path", "org.freedesktop.DBus.Introspectable", QDBusConnection::systemBus(), this); qDebug() << iface->call("Introspect").arguments();
  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    Why not use the parameters of currentItemChanged to get the current item ?

  • 0 Votes
    3 Posts
    1k Views
    J

    @juanki Gracias por tu respuesta, voy a estudiar la propuesta. Hace mil que no uso las clases abstractas y aun más el polimorfismo, me va a tocar quitarle el polvo a los apuntes de la universidad...

    ¿Tenéis más propuestas?

  • 0 Votes
    7 Posts
    2k Views
    mrjjM

    Hi
    Something like this could work, using a place holder for a label and a button
    will get you this
    http://postimg.org/image/9lhnsha15/
    you still need to hook up button&label for it to do something :)

    #include "mainwindow.h" #include <QApplication> #include <QCheckBox> #include <QRadioButton> #include <QPushButton> #include <QVBoxLayout> #include <QLabel> #include <QFile> #include <QMessageBox> #include <QTextStream> void CreateItem ( QListWidget * TheList , QString& TheText ) { QListWidgetItem * item = new QListWidgetItem ( "" ); TheList->addItem ( item ); // add a place hodler for label and button QWidget * w = new QWidget(); w->setLayout ( new QHBoxLayout() ); QPushButton *but = new QPushButton ( "Do it" ); QLabel *lab = new QLabel ( TheText ); // make row a bit bigger item->setSizeHint ( QSize ( item->sizeHint().width(), 30 ) ); // add the label and button to the layout w->layout()->addWidget ( lab ); w->layout()->addWidget ( but ); // reduce the space around it abit w->layout()->setContentsMargins ( 1, 1, 1, 1 ); // set this combined widget for the row TheList->setItemWidget ( item, w ); } int main ( int argc, char ** argv ) { QApplication app ( argc, argv ); QListWidget * list = new QListWidget(); list->setGeometry(50,50,400,200); QFile file ( "e:/mylist.txt" ); if ( !file.open ( QIODevice::ReadOnly ) ) { QMessageBox::information ( 0, "error", file.errorString() ); } QTextStream in ( &file ); while ( !in.atEnd() ) { QString line = in.readLine(); CreateItem ( list, line ); } file.close(); list->show(); return app.exec(); };
  • 0 Votes
    3 Posts
    889 Views
    R

    @SGaist Possibly, Thank you very much for giving me a starting point, or probably an answer!

  • 0 Votes
    6 Posts
    4k Views
    S

    @p3c0
    you are right it's better to use custom delegates like you say.
    I am not sure my solution runs with QListWidget but it is ok too with QTablewidget.

  • 0 Votes
    12 Posts
    4k Views
    p3c0P

    @ilyaik then I think my first post could be the possible way.