Search code examples
scrollqwidgetqt4.7qlistwidget

Qt- How to Draw Text from a QListWidget


Am Learning to do something with QListWidget. I have a QListWidget, QTextEdit , 2 QPushButtons (Add & Remove Buttons) and a QWidget for drawing the Text in it. When i enter a text in the QTextEdit and Click's the Add Button, the text has to add in the QListWidget. And from that QListWidget, i select any item and click's the Remove Button, the item has to be removed from the QListWidget. Then i want to draw this QListWidget Items in the QWidget and this drawed items has to scroll from Right to left. How can i do this? Plz help me...


Solution

  • //In the constructor
    WidgetString = "";
    
    On_add_button_Clicked() //SLOT
    {
     listwidget->addItem(lineedit->text());
    
    }
    
    On_Remove_Button_clicked() //SLOT
    {
     listWidget->takeItem(listWidget->currentIndex());
     //You may have to delete the the item taken in order to put that change into effect.
     //Trigger paintevent
    }
    
    on_listWidget_currentTextChanged(QString currentText) //SLOT
    {
     WidgetString = currentText;
    }
    
    paintevent()
    {
     QPainter painter(Your_Qwidget);
     painter.drawText ( int xPos, int YPos, WidgetString )
     update();
    }
    

    For the Scrollbar thing, you may need to increase the Text size you are going to Draw.