Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to add clickable text with outline and color to QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

How to add clickable text with outline and color to QGraphicsScene

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 744 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.
  • H Offline
    H Offline
    hdspider
    wrote on last edited by
    #1

    I am trying to make a clickable button like text appear on my QGraphicsScene.

    So far I have this. I want the T to be clickable and have an outline of my pen.I'd rather have an image imported and be clickable such as this
    And scale it to the size I like without losing much quality. I have no knowledge on how to import images and how to manipulate them so I chose to work with a text T as an alternative.

    import sys
    from PyQt5.QtWidgets import (QMainWindow, QApplication, QWidget, QPushButton, QAction,
                                 QComboBox, QDialog, QDialogButtonBox, QFormLayout, QGridLayout, QHBoxLayout,
                                 QLabel, QPushButton,
                                 QVBoxLayout, QFileDialog, QGroupBox, QGraphicsScene, QGraphicsView)
    from PyQt5.QtGui import QFont, QPixmap,QPainter, QPen, QBrush
    from PyQt5.QtCore import Qt,QRect, QSize, QDir
    
    class Test(QWidget):
        def __init__(self):
            super().__init__()
            self.title = 'Test '
            self.width = 1000
            self.height = 800
            self.gridSize = 20
    
            self.setGeometry(100, 100, self.width, self.height)
            self.setWindowTitle(self.title)
            self.initBoard()
            self.show()
    
        def initBoard(self):
            self.scene = QGraphicsScene()
            self.grayBrush = QBrush(Qt.black)
            self.pen = QPen(Qt.red)
            graphicsView = QGraphicsView(self.scene, self)
            graphicsView.setGeometry(0, 0, 800, 800)
            a = self.scene.addText("T", QFont("Sanserif", 100 * 0.66))
            a.setDefaultTextColor(Qt.gray)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        ex = Test()
        app.exec_()
    

    I am new to PyQt5. I don't really know how to weave multiple widgets like QPainter into QGraphics. I tried searching the documentation for making the text have an outline, but I couldn't find anything. I found this but its in C++ and I don't understand how to implement it. When he talks about paths, I don't know what that means. I also don't know how to implement QPainter inside of my QGraphics.

    I'm basically stuck because I don't know where to look and where I do find stuff, I can't make sense of it. Could someone give me a hand where I could find information on how to achieve my goal? Or tell me how I could go about it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Do you mean you want a button or a text like a hyperlink ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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