Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. painter event and combo box to draw lines
Forum Updated to NodeBB v4.3 + New Features

painter event and combo box to draw lines

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 306 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi,

    I have a paintEvent to draw lines. There is a ComboBox to select to draw line 1 or 2 . For ex. if the Combobox index is 0 draw line 1 or index 1 draw line 2. I did as follows

    void MainWindow::paintEvent(QPaintEvent *e)
    {
        QPainter painter1(this);
    
        QPen linepen1(Qt::darkRed);
        linepen1.setWidth(2);
    
    
        int comboVal = 0;
        comboVal = ui->comboBox->currentIndex(); // combo box value
    
        switch (comboVal)
        {
         case 0:
    
            painter1.setPen(linepen1);
            painter1.drawLine(p11,p12);
            break;
    
         case 1:
            
            painter1.setPen(linepen1);
            painter1.drawLine(p11,p13);
            break;
        }
    
    }
    

    The problem is that drawing is not "real-time" when selecting the Combobox index. Do you see an issue here?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Hi,

      Each time the combo value changes, you need to redraw the view by calling update().

      1 Reply Last reply
      2
      • V Offline
        V Offline
        viniltc
        wrote on last edited by
        #3

        @mpergand thanks a lot. update solves the issue!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved