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. Begin QGraphicsScene not from center, but from begining or how to make better

Begin QGraphicsScene not from center, but from begining or how to make better

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 479 Views
  • 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
    Vyivrain
    wrote on last edited by
    #1

    Hello, I have a problem with QGraphicsScene. I need to start it from the begining not from center. How can I do it? And is there a better solution? I tried to mathematically, but something else happens and when I change the size of qdialog something another happens( paints in another position relatively to cursor ). What I'm trying to make is simple paint, you press the button, what figure you want and then make 2 dots to draw that figure. Here's a part of the code that needs change:
    @void MyPaint::mousePressEvent(QMouseEvent *event)
    {
    QString temp;
    QPoint SomePoint = event->pos();
    if( event->button() == Qt::LeftButton && view->cursor().shape() == Qt::CrossCursor )
    {
    switch( pointsNum )
    {
    case 0:
    geom.push_back( QVector<QPoint>() );
    PushBackPoint( event->pos() );

        break;
    
        case 1:
            PushBackPoint( event->pos()  );
    
            if( lineButClicked || ellButClicked || rectButClicked )
            {
                Paint = true;
    
                this->update();
            }
        break;
        }
    }
    

    }

    void MyPaint::paintEvent(QPaintEvent *pe)
    {

    if( Paint )
    {
        QPainter painter( this );
        QPoint temp( view->pos() );
        QPoint correct( view->rect().width() / 2, view->rect().height() / 2 );
        if( lineButClicked )
        {
    
            items.push_back( scene->addLine( QLine(
                  geom[index][0] - temp - correct,
                  geom[index][1] - temp - correct   ) ) );
    
            index++;
            pointsNum = 0;
        }
        else if( ellButClicked )
        {
            scene->addRect( QRect( geom[index][0] - temp, geom[index][1] - temp ) );
            index++;
            pointsNum = 0;
        }
        else if ( rectButClicked )
        {
            scene->addEllipse( QRect( geom[index][0], geom[index][1] ) );
            index++;
            pointsNum = 0;
        }
        Paint = false;
    }
    

    }@
    Thx for answering, and is it ok to ask multiple questions in one thread, cause I think I'll be stuck in bugs for a long time? :)

    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