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. main widget's PaintEvent () method not painting custom widget

main widget's PaintEvent () method not painting custom widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 475 Views 1 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.
  • R Offline
    R Offline
    Ritz
    wrote on last edited by Ritz
    #1

    I have created a main widget and a custom widget. I am calling the custom widget from paintEvent() of main widget. so, my custom widget is not getting painted. But if i call the same custom widget from main widget's constructor then custom widget is getting painted. Please help!

       void HomeScreen::paintEvent(QPaintEvent *event){
          ......
         CustomWidget *c1=new CustomWidget(this,resList[j].name,resList[j].department,j*90,resList[j].contactNo,resList[j].emailId,resList[j].globalId,0,"RK");
         
             QListWidgetItem *item = new QListWidgetItem();
         
             lw->insertItem(lw->size().height(),item);
         
             item->setSizeHint(QSize(350,90));
         
             lw->setItemWidget(item,c1);
         
             this->update();
    }
    
    JonBJ 1 Reply Last reply
    0
    • R Ritz

      I have created a main widget and a custom widget. I am calling the custom widget from paintEvent() of main widget. so, my custom widget is not getting painted. But if i call the same custom widget from main widget's constructor then custom widget is getting painted. Please help!

         void HomeScreen::paintEvent(QPaintEvent *event){
            ......
           CustomWidget *c1=new CustomWidget(this,resList[j].name,resList[j].department,j*90,resList[j].contactNo,resList[j].emailId,resList[j].globalId,0,"RK");
           
               QListWidgetItem *item = new QListWidgetItem();
           
               lw->insertItem(lw->size().height(),item);
           
               item->setSizeHint(QSize(350,90));
           
               lw->setItemWidget(item,c1);
           
               this->update();
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Ritz
      Hello and welcome.

      I don't know why you are trying to do as you are, but a widget's paintEvent() is surely not the place to be creating new widgets and inserting them into the UI. Paint events should just paint.

      R 1 Reply Last reply
      0
      • JonBJ JonB

        @Ritz
        Hello and welcome.

        I don't know why you are trying to do as you are, but a widget's paintEvent() is surely not the place to be creating new widgets and inserting them into the UI. Paint events should just paint.

        R Offline
        R Offline
        Ritz
        wrote on last edited by Ritz
        #3

        @JonB Thank you!
        I was trying to call my custom widget from a method. The method was creating the custom widget but it was not reflected on the main widget UI.

        JonBJ 1 Reply Last reply
        0
        • R Ritz

          @JonB Thank you!
          I was trying to call my custom widget from a method. The method was creating the custom widget but it was not reflected on the main widget UI.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Ritz
          You want/need to create your widget --- or any widget --- from a suitable method/function/place. So indeed, for example, the main widget's constructor is suitable, or from some slot if you only want it constructed in response to some signal. But a paintEvent() is not a suitable place.

          Given this, do you actually have any question once you have moved your code elsewhere?

          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