Why don't I get an updated list of values via drawShapes



  • lottery.cpp

    when I hit select drawShapes does not update 54 values

    @
    #include "lottery.h"
    #include <QSet>
    #include <QtDebug>
    #include <QPainter>

    Lottery::Lottery(QWidget *parent)
    : QWidget(parent)
    {
    ui.setupUi(this);
    connect( ui.pushButton, SIGNAL(clicked()), this, SLOT(selectClicked()) );
    }

    Lottery::~Lottery()
    {

    }
    void Lottery::selectClicked()
    {
    int value;
    int M = 53;
    int intArray[6];
    QSet<int> set;
    set.reserve(6);
    srand(time(0));
    ui.listWidget->addItem(QString("server StartTCPServer"));
    do
    {
    value = (int)( M*(double)rand()/((double)RAND_MAX+(double)1))+1;

     set.insert(value);
    } while(set.size()<6);
    
    
    int j = 0;
    QSet<int>::const_iterator i = set.begin();
    while (i != set.end()) {
        intArray[j] = *i;
        histo[intArray[j]]++;
        ++i;++j;
    }
    QString qstring1;
    qstring1.setNum(intArray[0]);
    ui.lineEdit_1->setText(qstring1);
    
    qstring1.setNum(intArray[1]);
    ui.lineEdit_2->setText(qstring1);
     
    qstring1.setNum(intArray[2]);
    ui.lineEdit_3->setText(qstring1);
      
    qstring1.setNum(intArray[3]);
    ui.lineEdit_4->setText(qstring1);
       
    qstring1.setNum(intArray[4]);
    ui.lineEdit_5->setText(qstring1);
        
    qstring1.setNum(intArray[5]);
    ui.lineEdit_6->setText(qstring1);
    
    QPainter paint( this );
    drawShapes(&paint);
    

    }
    void Lottery::paintEvent( QPaintEvent* qpe) {
    // fout<<"DrawView::paintEvent"<<endl;

    QPainter paint( this );
    drawShapes(&paint);
    qpaintevent = qpe;
    

    }
    void Lottery::drawShapes( QPainter *p ) {
    setGeometry(100,100,800,800);
    p->setPen( Qt::black);
    QFont qf;
    qf.setStyle(QFont::StyleNormal);
    qf.setWeight(QFont::Light);
    p->setFont(qf);
    QString qstr1;
    QString qstr2;
    int ix = 300;
    int iy = 20;
    for(int i = 1; i<54;i++)
    {
    qstr1.setNum(i);
    qstr2.setNum(histo[i]);
    p->drawText(ix, iy,"number of "+qstr1+"="+qstr2);
    iy+=15;
    }

    }

    @

    lottery,h

    @

    #ifndef LOTTERY_H
    #define LOTTERY_H

    #include <QtGui/QWidget>
    #include "ui_lottery.h"
    #include <QMap>
    #include <QPaintEvent>
    class Lottery : public QWidget
    {
    Q_OBJECT

    public:
    Lottery(QWidget *parent = 0);
    ~Lottery();

    private:
    Ui::LotteryClass ui;
    void paintEvent( QPaintEvent * );
    QMap<int,int> histo;
    QPaintEvent* qpaintevent;
    void drawShapes( QPainter *p );
    private slots:
    void selectClicked();
    };

    #endif // LOTTERY_H
    @


  • Moderators

    How many are you getting?

    Your draw loop at line 83 above has:
    @
    for(int i = 1; i<54;i++)
    @

    which will only draw 53 items, skipping element 0.



  • I get 53 values right out of the starting gate all zero of course

    when I hit the select button, the "histogram" values are not updated

    with the current lottery values

    If I minimize/maximize, the values are updated

    drawShapes needs a paintEvent I guess

    if you win a lottery using my program, you owe me half...ha!



  • there are 53 values in the lottery for each of 6 positions

    not 54...sorry!

    1-53

    @
    /********************************************************************************
    ** Form generated from reading UI file 'lottery.ui'
    **
    ** Created by: Qt User Interface Compiler version 4.8.1
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/

    #ifndef UI_LOTTERY_H
    #define UI_LOTTERY_H

    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLineEdit>
    #include <QtGui/QListWidget>
    #include <QtGui/QPushButton>
    #include <QtGui/QVBoxLayout>
    #include <QtGui/QWidget>

    QT_BEGIN_NAMESPACE

    class Ui_LotteryClass
    {
    public:
    QPushButton *pushButton;
    QPushButton *pushButtonClose;
    QWidget *layoutWidget;
    QVBoxLayout *verticalLayout;
    QLineEdit *lineEdit_1;
    QLineEdit *lineEdit_2;
    QLineEdit *lineEdit_3;
    QLineEdit *lineEdit_4;
    QLineEdit *lineEdit_5;
    QLineEdit *lineEdit_6;
    QListWidget *listWidget;

    void setupUi(QWidget *LotteryClass)
    {
        if (LotteryClass->objectName().isEmpty())
            LotteryClass->setObjectName(QString::fromUtf8("LotteryClass"));
        LotteryClass->resize(400, 528);
        QFont font;
        font.setBold(true);
        font.setWeight(75);
        LotteryClass->setFont(font);
        LotteryClass->setMouseTracking(false);
        pushButton = new QPushButton(LotteryClass);
        pushButton->setObjectName(QString::fromUtf8("pushButton"));
        pushButton->setGeometry(QRect(70, 230, 83, 30));
        pushButtonClose = new QPushButton(LotteryClass);
        pushButtonClose->setObjectName(QString::fromUtf8("pushButtonClose"));
        pushButtonClose->setGeometry(QRect(70, 290, 83, 30));
        layoutWidget = new QWidget(LotteryClass);
        layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
        layoutWidget->setGeometry(QRect(40, 20, 146, 194));
        verticalLayout = new QVBoxLayout(layoutWidget);
        verticalLayout->setSpacing(6);
        verticalLayout->setContentsMargins(11, 11, 11, 11);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        verticalLayout->setContentsMargins(0, 0, 0, 0);
        lineEdit_1 = new QLineEdit(layoutWidget);
        lineEdit_1->setObjectName(QString::fromUtf8("lineEdit_1"));
    
        verticalLayout->addWidget(lineEdit_1);
    
        lineEdit_2 = new QLineEdit(layoutWidget);
        lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
    
        verticalLayout->addWidget(lineEdit_2);
    
        lineEdit_3 = new QLineEdit(layoutWidget);
        lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
    
        verticalLayout->addWidget(lineEdit_3);
    
        lineEdit_4 = new QLineEdit(layoutWidget);
        lineEdit_4->setObjectName(QString::fromUtf8("lineEdit_4"));
    
        verticalLayout->addWidget(lineEdit_4);
    
        lineEdit_5 = new QLineEdit(layoutWidget);
        lineEdit_5->setObjectName(QString::fromUtf8("lineEdit_5"));
    
        verticalLayout->addWidget(lineEdit_5);
    
        lineEdit_6 = new QLineEdit(layoutWidget);
        lineEdit_6->setObjectName(QString::fromUtf8("lineEdit_6"));
    
        verticalLayout->addWidget(lineEdit_6);
    
        listWidget = new QListWidget(LotteryClass);
        listWidget->setObjectName(QString::fromUtf8("listWidget"));
        listWidget->setGeometry(QRect(70, 330, 171, 111));
    
        retranslateUi(LotteryClass);
        QObject::connect(pushButtonClose, SIGNAL(clicked()), LotteryClass, SLOT(close()));
    
        QMetaObject::connectSlotsByName(LotteryClass);
    } // setupUi
    
    void retranslateUi(QWidget *LotteryClass)
    {
        LotteryClass->setWindowTitle(QApplication::translate("LotteryClass", "Lottery", 0, QApplication::UnicodeUTF8));
        pushButton->setText(QApplication::translate("LotteryClass", "select", 0, QApplication::UnicodeUTF8));
        pushButtonClose->setText(QApplication::translate("LotteryClass", "Close", 0, QApplication::UnicodeUTF8));
    } // retranslateUi
    

    };

    namespace Ui {
    class LotteryClass: public Ui_LotteryClass {};
    } // namespace Ui

    QT_END_NAMESPACE

    #endif // UI_LOTTERY_H

    @


  • Moderators

    Instead of doing:
    @
    QPainter paint( this );
    drawShapes(&paint);
    @

    in your selectClicked() method, use
    @
    repaint();
    @



  • ui_lottery.h
    @
    <ui version="4.0" >
    <class>LotteryClass</class>
    <widget class="QWidget" name="LotteryClass" >
    <property name="geometry" >
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>528</height>
    </rect>
    </property>
    <property name="font" >
    <font>
    <weight>75</weight>
    <bold>true</bold>
    </font>
    </property>
    <property name="mouseTracking" >
    <bool>false</bool>
    </property>
    <property name="windowTitle" >
    <string>Lottery</string>
    </property>
    <widget class="QPushButton" name="pushButton" >
    <property name="geometry" >
    <rect>
    <x>70</x>
    <y>230</y>
    <width>83</width>
    <height>30</height>
    </rect>
    </property>
    <property name="text" >
    <string>select</string>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButtonClose" >
    <property name="geometry" >
    <rect>
    <x>70</x>
    <y>290</y>
    <width>83</width>
    <height>30</height>
    </rect>
    </property>
    <property name="text" >
    <string>Close</string>
    </property>
    </widget>
    <widget class="QWidget" name="layoutWidget" >
    <property name="geometry" >
    <rect>
    <x>40</x>
    <y>20</y>
    <width>146</width>
    <height>194</height>
    </rect>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout" >
    <item>
    <widget class="QLineEdit" name="lineEdit_1" />
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_2" />
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_3" />
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_4" />
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_5" />
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_6" />
    </item>
    </layout>
    </widget>
    <widget class="QListWidget" name="listWidget" >
    <property name="geometry" >
    <rect>
    <x>70</x>
    <y>330</y>
    <width>171</width>
    <height>111</height>
    </rect>
    </property>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11" />
    <resources/>
    <connections>
    <connection>
    <sender>pushButtonClose</sender>
    <signal>clicked()</signal>
    <receiver>LotteryClass</receiver>
    <slot>close()</slot>
    <hints>
    <hint type="sourcelabel" >
    <x>111</x>
    <y>304</y>
    </hint>
    <hint type="destinationlabel" >
    <x>199</x>
    <y>263</y>
    </hint>
    </hints>
    </connection>
    </connections>
    </ui>
    @



  • sorry the range for each lottery entry is 1-53

    in each of the 6 positions

    Not a lottery player but it is great learning tool

    when I click on select, I should get the 53 values in the histogram updated



  • by Jove Olde Beane...think you got it

    it works! thanks!

    I had tried repaint() but put it in the wrong place


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.